|
Strings
|
String variableName = "Text in here"; |
|
Integers
|
int variableName = 0; |
|
Doubles
|
double variableName = 0.1; |
|
Longs
|
long variableName = 999999999; |
|
Booleans
|
boolean variableName = false; |
String variableName; will create a new empty String variable.
|
Array that can hold 4 Strings
|
string[4] array; |
|
Array with pre-set content
|
string[3] array = {"Banana", "Orange", "Apple"} |
|
Access the nth value of an array
|
array[n-1]; |
|
Assign a value to an array
|
array[n-1] = "Pear"; |
|
Create a new String variable
|
String variableName; |
|
Assign "Pear" to the variable
|
variableName = "Pear"; |
"Pear" to an int, for example.
|
While loops will repeatedly run the code inside it until the
condition is false, in which the loop will stop and the code after it will continue. |
while (condition) { // code here}
|
Declare a function
|
void myFunc() |
|
Declare a function that returns an
int |
int myFunc(){ |
|
Declare a function that takes a String parameter
|
void myFunc(String param) { |
|
Store the return value of a function in a variable
|
int variableName = myFunc(); |
int value with a String parameter, for example. Use void if your function doesn't return anything.
|
Set digital pin
n to INPUT. |
pinMode(n, INPUT); |
|
Set digital pin
n to OUTPUT. |
pinMode(n, OUTPUT); |
|
Read digital pin
n (returns boolean) |
digitalRead(n); |
|
Write to digital pin
n (LOW or HIGH) |
digitalWrite(n, LOW); |
|
Read value of analog pin A0 (returns int)
|
analogRead(A0); |
|
Create a new motor plugged into port M1
|
Adafruit_DCMotor *myMotor = AFMS.getMotor(1); |
|
Set speed of a motor (0-255)
|
motor->setSpeed(100); |
|
Change motor direction (FORWARD, BACKWARD, RELEASE)
|
motor->run(FORWARD); |
|
Create a new encoder plugged in pins 2 and 3
|
Encoder myEncoder(2, 3); |
|
Read encoder (returns long)
|
Encoder.read(); |
|
Write to encoder
|
Encoder.write(0); |
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.