1 / 55

TOOLBAR

TOOLBAR . TABS. TEXT EDITOR. MESSAGE. CONSOLE. DISPLAY WINDOW. PLAY. STOP. NEW. OPEN. SAVE. EXPORT. STRUCTURE. A variable is a place to store a piece of data. It has a name, a value, and a type. STRUCTURE.

joey
Download Presentation

TOOLBAR

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TOOLBAR TABS TEXT EDITOR MESSAGE CONSOLE

  2. DISPLAY WINDOW

  3. PLAY STOP NEW OPEN SAVE EXPORT

  4. STRUCTURE Avariableis a place to store a piece of data. It has a name, a value, and a type.

  5. STRUCTURE Avariableis a place to store a piece of data. It has a name, a value, and a type. The setup() Called once when the program is started. Used to define initial enviroNment properties such as screen size, background color, loading images, etc. before the draw() begins executing. Variables declared within setup() are not accessible within other functions, includingdraw(). There can only be one setup() function for each program and it should not be called again after it's initial execution.

  6. STRUCTURE Avariableis a place to store a piece of data. It has a name, a value, and a type. The setup() Called once when the program is started. Used to define initial enviroNment properties such as screen size, background color, loading images, etc. before the draw() begins executing. Variables declared within setup() are not accessible within other functions, includingdraw(). There can only be one setup() function for each program and it should not be called again after it's initial execution. Draw () Called directly after setup() and continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called. The draw() function is called automatically and should never be called explicitly. The number of times draw() executes in each second may be controlled with the delay() and frameRate() functions. *note the word void means the process does not return a value *note the () are used to insert parameters

  7. SYNTAX The curly brackets { and } denote the beginning and the end of each process

  8. SYNTAX The curly brackets { and } denote the beginning and the end of each process Comments Comments are ignored by the computer, but useful for communicating complex procedures // two forwards slashes denote comments // all text on the same line will be ignored /* a forward slash followed by an asterisk allows for a continuous comment until the reverse */

  9. SYNTAX The curly brackets { and } denote the beginning and the end of each process Comments Comments are ignored by the computer, but useful for communicating complex procedures // two forwards slashes denote comments // all text on the same line will be ignored /* a forward slash followed by an asterisk allows for a continuous comment until the reverse */ ; Denotes the end of a statement and must be used for all expressions

  10. VARIABLES

  11. Syntax Expressions intlight=analogRead(0); Data type constant operator function parameter statementterminator

  12. Variable Types variables to hold data. Variables can be of different types: whole numbers are referred to as integer variables, true/false data is Referred to as Booleans, and factional numbers are floats

  13. Name Conventions When we declare a variable (which is a made up name) we also need to tell what type it is and (if needed) to give it an initial value. We use the following format: type name = value; For example: intthisClass= 24; Variables usually start with lower case and when we want to composite more than one word, we use upper case for the next word. This is also referred to as intercapping. For example: names or newNames or newPeopleNames Caution: A name cannot start with a number, contain an empty space or any special characters except the underscore. For example 1thing, x-y, or the plan is invalid names, but thing1, x_y and the_plan are valid names.

  14. boolean,which is 1-bit long and can take values of either true or false booleanisInside = false;

  15. char,which is 16-bit long and therefore can store 216 (= 65,536) different Characters (assuming that each character corresponds to one number which is its ASCII code) char firstLetter = ‘A’;

  16. byte, which is an 8-bit element and therefore can store 28 (=256) different binary patterns. byte b = 20;

  17. int, which is 32-bit long can define integer (whole) numbers Integers can be as large as 2,147,483,647 and as low as -2,147,483,648 intnumber_of_squares = 25;

  18. float, which is 32-bits long can define real numbers Floating-point numbers can be as large as 3.40282347E+38 and as low as -3.40282347E+38. float pi = 3.14;

  19. Long, which is 64-bits long can define large integers (whole) numbers. • A long integer has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807  • long a = 100000; • Arduino uses unsigned longs. Unlike standard longs unsigned longs are 32 bit and won't store negative numbers, making their range from 0 to 4,294,967,295 • Unsigned long = 100000;

  20. color, which is a group of three numbers to define a color using red, green, and blue. Each number is between 0 and 255. color c = color(255, 0, 0); Or color r = red(pixel[i])

  21. String, which is a collection of characters used for words and phrases String myName = ”Jpnathan";

  22. *NOTE TYPE SIZE DESCRIPTION boolean 1-bit True or false char 16-bits Keyboard characters byte 8-bits or 1-byte 0-255 numbers int 32-bits Integer numbers float 32-bits Real fractional numbers color 4 bytes or 32-bytes Red, Green, Blue, and Transparency String 64-bits Set of characters that form words

  23. Cast A variable of one type can be cast (i.e. converted) to another type. For example, float dist = 3.5; intx = int(dist); the value of the float variable dist can be cast to an integer one x. After the casting x will be 3 (i.e. the fractional or decimal part is omitted). The following command allows casting between different types: boolean(), int(), float(), str(), byte(). For example, float dist = 3.5; String s = str(dist); will create the string value "3.5" (not the float number 3.5).

  24. For booleans we usually start with the prefix “is”. For example: isLightOn or isItRaining

  25. As an example of initializing variables and data let’s define information about a circle. The following types, variables, and initializations can be used: String name = "MyCircle"; intlocation_x = 22; intlocation_y = 56; float radius = 4.5; Boolean isNurbs = false;

  26. GETTING STARTED

  27. OPERATIONS

  28. Arithmetic Operations OPERATOR USE DESCRIPTION + op1 + op2 //Adds op1 and op2 - op1 - op2 //Subtracts op2 from op1 * op1 * op2 // Multiplies op1 by op2 / op1 / op2 // Divides op1 by op2 % 1op1 % op2 //Computes the remainder of dividing op1 by op2

  29. The sequence in which the operations will be executed follows the order (,),*, /,%, +, - postfix operators ( ) multiplicative * / % additive + -

  30. Shortcuts x+=1 is equivalent to x=x+1 or y/=z is equivalent to y=y/z. OPERATOR USE EQUIVALENT TO += op1 += op2 op1 = op1 + op2 -= op1 -= op2 op1 = op1 - op2 *= op1 *= op2 op1 = op1 * op2 /= op1 /= op2 op1 = op1 / op2 %= op1 %= op2 op1 = op1 % op2

  31. Logical and relational operations/statements Logical operations define the truthfulness of something. For example the word if represents a guess that needs to be tested. In Processing if-statements have the following format: if( condition ) …; else …;

  32. if (pinFiveInput < 500) { // do Thing A } else if (pinFiveInput >= 1000) { // do Thing B } else { // do Thing C }

  33. if(a==b) // if a is equal tob if(a!=b) // if a is not equal to b if(a>b) // if a is greater than to b if(a>=b) // if a is greater than or equal to b if(a<b) // if a isless than b if(a<=b) // if a is less than or equal to b * Note we use ‘=‘ when assigning values as in char name = jonathan

  34. To combine conditions, we use the AND and OR operators represented by && and || symbols. For example if(a>b && a >c) // if a is greater than band a is greater than c if(a>b || a >c) / // if a is greater than bor a is greater than c If(!a) / // if not a (a having been declared)

  35. A loop is a repetition of statements. It allows statements to be defined, modified, or executed repeatedly until a termination condition is met.

  36. for(start condition; end condition; modification step){ ….; } For example a loop from 0 to 9 is: for(inti=0; i<10; i=i+1){ println(i); // will printout the value of i } i=i+1 i++ i+=1 0123456789

  37. The while statement continually executes a block of statements while a condition remains true. The syntax is: while (expression) { statement }

  38. The while statement evaluates expression, which must return a booleanvalue. If the expression returns as true, then the while statement executes the statement(s) associated with it. The while statement continues testing the expression and executing its block until the expression returns as false. For example, in the loop inti=0; while(i<10){ println(i); // will printout i i++; } the result is: 0123456789

  39. Two more commands are associated with loops: continue and break. The continue command skips the current iteration of a loop. The break command will force to exit the loop. For example, consider the following loop: for(inti=0; i<10; i++){ if(i==5)continue; if(i==8) break; println(i); // will printout the value of i } The result will be 0123467. The reason is that when i becomes 5 the rest of the statements are skipped and when i becomes 8 the loop is forced to exit.

  40. Two more commands are associated with loops: continue and break. The continue command skips the current iteration of a loop. The break command will force to exit the loop. For example, consider the following loop: for(inti=0; i<10; i++){ if(i==5)continue; if(i==8) break; println(i); // will printout the value of i } The result will be 0123467. The reason is that when i becomes 5 the rest of the statements are skipped and when i becomes 8 the loop is forced to exit.

  41. boolean A boolean holds one of two values, true or false. (Each boolean variable occupies one byte of memory.)

  42. delay() Description Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.) Syntax delay(ms) Parameters ms: the number of milliseconds to pause (unsigned long) Returns nothing

  43. simple FUNCTIONS

  44. Normalizing, divides value by the maximum value within a set i.e. returns a value Between 0.0 and 1.0 norm(value, low,high) float x = norm(102.0, 0.0,255.0); // x = .4 (note once declared ‘x’ does not need to be preceded by ‘float’ Once normalized values can be applied to a range using simple arithmetic Range 0.0 to 255.0 X* 255.0 .4* 255.0 = 102.0

  45. Constrain, constrains a value within a range constrain(value, min, max) float x = constrain(102.0, 0.0,100.0); // x = 100.0

  46. map, re-maps one range of values to another range of values constrains a value *note map will not constrain values map(value, fromMin, fromMax,toMin,toMax) float x = map(.4, 0.0,1.0, 0.0,255.0); // x = 102.0

More Related