2015 YAAYS Tech Camp Reference Sheet
[ ] = syntax location: B = before setup, S = setup, L = loop
* = line is required when using digital (D) or analog (A) components
Thing Example(s) (bold text = variables)
[B] Variables (assigning pins / naming number values / combining other variables) | int componentName = pinNumber; *D/A* int variableName = anyNumber; int newVariable = variable1 + variable2; |
[L] Timing (loop runs everything before each delay for stated time) | delay(number in milliseconds); |
[S] Pin Mode (tells specified pin to be an input or an output) | pinMode(componentName, INPUT / OUTPUT); *D* |
[L] Digital Write (tells specified pin to be high or low) | digitalWrite(componentName, HIGH / LOW); |
[L] Digital Read (reads pin state, returns TRUE or FALSE) | variableName = digitalRead(componentName); |
[L] Analog Read (reads pin value, returns 0 - 1023) | variableName = analogRead(componentName); |
[B] Including Servos (call servo library / names servo variable) | #include <Servo.h> Servo servoName; |
[S] Servo Setup (attaches pins) | servoName.attach(pinNumber); |
[L] Moving Servos | servoName.write(number 0 - 180); |
[L] If Statement | if (thing1 comparisonOperator thing2) { do_this; } |
[L] Using RGB LEDs (info inside comment) | setColor(255, 0, 0); /* setColor is the name of a function you need when using RGB LEDs. Each of the three numbers must be from 0 - 255, and represent the amount of red, green, or blue put into the LED /* |
[B] setColor Function (how to write your own function) [L] Calling Your Functions __________________________ functionName(); | void setColor(int red, int green, int blue) { analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); } |
*If you want to view the programming powerpoint, the link is “bit.ly/yaays2015”*