ARDUINO CHEAT SHEET
For more information visit: [Link]
Structure Data \ Variable Types Advanced I\O Arduino Uno / SparkFun Redboard
/* Each Arduino sketch must void (null) tone(pin, freq); Pin Layout
contain the following two boolean (0, 1, false, true) /* Generates a square wave of
functions */ char (8 bits: ASCII character) the specified frequency to a
void setup() byte (8 bits: 0 to 255) pin. Pin must be one of the
{ int (integer -32,768 to 32,767) PWM (~) pins. */
// runs only once. long (long int -2,147,483,648
} to 2,147,483,647) tone(pin, freq, duration);
void loop() float (floating point / decimal /* Generates a frequency to a
{ numbers) pin for a specified duration in
// runs repeatedly. String (array of characters) milliseconds. */
}
Global Constants noTone(pin);
Comments/Debug HIGH \ LOW /* Turns off the tone on pin.
/* this is a multiline comment. INPUT \ OUTPUT */
nothing between here will be true \ false
run or executed */ Time & Timing
// this is a single Basic I/O delay(time_ms);
// line comment /* Pauses the program for the
INPUT - Reading voltages
amount of time(in milliseconds)
sensorVal = digitalRead(pin);
Control Structures */
/* Reads the voltage at the
if(condition) specific digital pin, returns
delayMicroseconds(us); Serial Communication
{ either HIGH or LOW */
// if condition is TRUE, do /* Pauses the program for the [Link](baudrate);
amount of time(in microseconds) /* Initializes serial com on
} sensorVal = analogRead(pin);
*/ pins 0 and 1 at the baudrate.
else /* Reads the voltage at the
{ specific analog pin (A0 to A5), Typical rate is 9600 */
t = millis();
// otherwise, do this returns a value from 0 to 1023
/* Returns the number of [Link](data);
} */ milliseconds since the board /* prints data to serial
began running the current terminal. Typically sends out
OUTPUT - Setting voltages program. max: 4,294,967,295 */ to the Arduino serial monitor
for(init var; condition; increm)
digitalWrite(pin, val); */
{
/* Sets the voltage on a pin to t = delayMicroseconds(us);
// do this
HIGH or LOW based on val. val /* Returns the number of [Link](data);
}
can be HIGH or LOW.*/ microseconds since the board /* prints data to serial
began running the current terminal and includes a CRLF */
analogWrite(pin, val); program. max: 4,294,967,295 */
/* Sets the voltage on a PWM [Link]()
pin (~) based on val. val can /* returns a true if data is
be an integer from 0 to 255. */ Servo myServo; available on the serial bus */
/* creates an object called
Servo Library myServo */ data = [Link]();
#include<Servo.h> [Link](pin); /* Reads a single byte from the
/* pre-compiler directive. /* sets up a servo controlled serial bus */
includes additional code for by pin */
using special functions. Note [Link](angle);
no ; at the end. */ /* sets the servo to move to
specified angle. */