Arduino Sheet (Verso)
Arduino Sheet (Verso)
RedBoard:
Structure Digital I/O Data Types
/* Each Arduino sketch must contain the digitalWrite(pin, val); void // nothing is returned
following two functions. */ /* val = HIGH or LOW write a HIGH or a LOW boolean // 0, 1, false, true
void setup() value to a digital pin. */ char // 8 bits: ASCII character Power In USB to Computer
{ int var = digitalRead(pin); byte // 8 bits: 0 to 255, unsigned
/* this code runs once at the beginning of /* Reads the value from a specified digital Reset
int // 16 bits: 32,768 to 32,767, signed
the code execution. */ pin, either HIGH or LOW. */
long /* 32 bits: 2,147,483,648
} to 2,147,483,647, signed */
Analog I/O float // 32 bits, signed decimal
void loop() analogWrite(pin, val);
{ /* Writes an analog value to a pin.
Constants SCL/SDA
/* this code runs repeatedly over and over val = integer value from 0 to 255 */ (I2C Bus)
HIGH \ LOW
as long as the board is powered. */ int var = analogRead(pin);
INPUT \ OUTPUT
} /* Reads the value from the specified
analog pin. */ true \ false
Comments
Advanced I/O Mathematical Operators Power
// this is a single line 5V / 3.3 / GND Digital I/O
tone(pin, freq); = // assignment
/* this is PWM(3,5,6,9,10,11)
/* Generates a square wave of the specified + // addition
a multiline */
frequency to a pin. Pin must be one of the - // subtraction Analog
PWM (~) pins. */ * // multiplication Inputs
Setup tone(pin, freq, duration); / // division
pinMode(pin, [INPUT \ OUTPUT \ INPUT_PUL- /* Generates a square wave of the specified % // modulus
LUP]); frequency to a pin for a duration in ATmega328
/* Sets the mode of the digital I/O pin. Microcontroller
milliseconds. Pin must be one of the PWM (~)
It can be set as an input, output, or an pins. */
Logical Operators
input with an internal pull-up resistor. noTone(pin); == // boolean equal to
*/ // Turns off the tone on the pin. != // not equal to
< // less than LilyPad ProtoSnap Simple:
Control Structures Time > // greater than
if(condition) delay(time_ms); <= // less than or equal to
{ /* Pauses the program for the amount of time >= // greater than or equal to
// if condition is TRUE, do something here (in milliseconds). */ && // Boolean AND RGB LED
} delayMicroseconds(time_us); || // Boolean OR Switch Button Vibe Motor
else /* Pauses the program for the amount of time ! // Boolean NOT
{ (in microseconds). */
// otherwise, do this millis(); Bitwise Operators
} /* Returns the number of milliseconds since
& // bitwise AND
the board began running the current program.
max: 4,294,967,295 */
| // bitwise OR
for(initialization; condition; increment) ^ // bitwise XOR
{ micros();
/* Returns the number of microseconds since ~ // bitwise INVERT
// do this
the board began running the current program. var << n // bitwise shift left by n bits LEDs
} max: 4,294,967,295 */ var >> n // bitwise shift right by n bits (Light Emitting Diodes)
/* The ‘for’ statement is used to repeat
a block of statements enclosed in curly
braces. An increment counter is usually
Libraries
used to increment and terminate the loop. #include <libraryname.h>
*/ /* this provides access to special
additional functions for things such as
servo motors, SD card, wifi, or bluetooth. ATmega328
*/ Microcontroller