Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Arduino BBR

Primary source: Arduino Language Reference

Programming Cheat Sheet WWW.E2CRE8.BE >> BBR


https://arduino.cc/en/Reference/

Structure & Flow Operators Built-in Functions Libraries


Basic Program Structure General Operators Pin Input/Output Math Serial - comm. with PC or via RX/TX
void setup() { = assignment Digital I/O - pins 0-13 A0-A5 min(x, y) max(x, y) abs(x) begin(long speed) // Up to 115200
// Runs once when sketch starts + add - subtract pinMode(pin, sin(rad) cos(rad) tan(rad) end()
} * multiply / divide [INPUT, OUTPUT, INPUT_PULLUP]) sqrt(x) pow(base, exponent) int available() // #bytes available
void loop() { % modulo int digitalRead(pin) constrain(x, minval, maxval) int read() // -1 if none available
// Runs repeatedly == equal to != not equal to digitalWrite(pin, [HIGH, LOW]) map(val, fromL, fromH, toL, toH) int peek() // Read w/o removing
} < less than > greater than flush()
<= less than or equal to Analog In - pins A0-A5 Random Numbers print(data) println(data)
Control Structures >= greater than or equal to int analogRead(pin) randomSeed(seed) // long or int write(byte) write(char * string)
if (x < 5) { ... } else { ... } && and || or analogReference( long random(max) // 0 to max-1 write(byte * data, size)
while (x < 5) { ... } ! not [DEFAULT, INTERNAL, EXTERNAL]) long random(min, max) SerialEvent() // Called if data rdy
for (int i = 0; i < 10; i++) { ... }
break; // Exit a loop immediately Compound Operators PWM Out - pins 3 5 6 9 10 11 SoftwareSerial.h - comm. on any pin
Bits and Bytes
continue; // Go to next iteration ++ increment analogWrite(pin, value) SoftwareSerial(rxPin, txPin)
lowByte(x) highByte(x)
switch (var) { -- decrement begin(long speed) // Up to 115200
bitRead(x, bitn)
case 1: += compound addition listen() // Only 1 can listen
Advanced I/O bitWrite(x, bitn, bit)
... -= compound subtraction isListening() // at a time.
tone(pin, freq_Hz) bitSet(x, bitn)
break; *= compound multiplication read, peek, print, println, write
tone(pin, freq_Hz, duration_ms) bitClear(x, bitn)
case 2: /= compound division // Equivalent to Serial library
noTone(pin) bit(bitn) // bitn: 0=LSB 7=MSB
... &= compound bitwise and
shiftOut(dataPin, clockPin,
break; |= compound bitwise or EEPROM.h - access non-volatile memory
[MSBFIRST, LSBFIRST], value) Type Conversions
default: byte read(addr)
unsigned long pulseIn(pin, char(val) byte(val)
... Bitwise Operators write(addr, byte)
[HIGH, LOW]) int(val) word(val)
} & bitwise and | bitwise or EEPROM[index] // Access as array
return x; // x must match return type long(val) float(val)
^ bitwise xor ~ bitwise not
return; // For void return type << shift left >> shift right Time
Servo.h - control servo motors
unsigned long millis() External Interrupts
attach(pin, [min_uS, max_uS])
Function Definitions Pointer Access // Overflows at 50 days attachInterrupt(interrupt, func,
write(angle) // 0 to 180
<ret. type> <name>(<params>) { ... } & reference: get a pointer unsigned long micros() [LOW, CHANGE, RISING, FALLING])
writeMicroseconds(uS)
e.g. int double(int x) {return x*2;} * dereference: follow a pointer // Overflows at 70 minutes detachInterrupt(interrupt)
// 1000-2000; 1500 is midpoint
delay(msec) interrupts()
int read() // 0 to 180
delayMicroseconds(usec) noInterrupts()
bool attached()
Variables, Arrays, and Data detach()
2 IR DISTANCE SENSOR
Data Types Numeric Constants 2 LIGHT SENSOR Wire.h - I²C communication
boolean true | false 123 decimal 2 LINE SENSOR begin() // Join a master
char -128 - 127, 'a' '$' etc. 0b01111011 binary begin(addr) // Join a slave @ addr
LINKS RECHTS
unsigned char 0 - 255 0173 octal - base 8 requestFrom(address, count)
4 12
byte 0 - 255 0x7B hexadecimal - base 16 beginTransmission(addr) // Step 1
-32768 - 32767 123U force unsigned send(byte) // Step 2
A0

int

A1
A2

A3
unsigned int 0 - 65535 123L force long send(char * string)

10
9

word 0 - 65535 123UL force unsigned long send(byte * data, size)


4 LEDS
long -2147483648 - 2147483647 123.0 force floating point 8 22 endTransmission() // Step 3
unsigned long 0 - 4294967295 1.23e6 1.23*10^6 = 1230000 int available() // #bytes available
11 13 30 17
float -3.4028e+38 - 3.4028e+38 byte receive() // Get next byte
Qualifiers RESET onReceive(handler)
double currently same as float
static persists between calls 5V onRequest(handler)
void i.e., no return value ATMEGA32U4
USB
volatile in RAM (nice for ISR) J2 9
10 ARDUINO 7
const read-only
15
23

J1 15 LEONARDO BUZZER

Strings 23
PROGMEM in flash
char str1[8] = 5V
GND
EXTRA
GND
DRIVER
5V
GND
by Bart Huyskens
{'A','r','d','u','i','n','o','\0'}; Arrays SERVO
RX RS232 version: 08/01/2018
5V OK

// Includes \0 null termination int myPins[] = {2, 4, 8, 3, 6}; TX HC06 BT, ...
source: h ps://github.com/liffiton/Arduino-Cheat-Sheet/
6-PWM

5-PWM

char str2[8] = int myInts[6]; // Array of 6 ints


GND
6.2V

GND

SDA
SCL
5V
14

16

{'A','r','d','u','i','n','o'}; myInts[0] = 42; // Assigning first


MICRO
// Compiler adds null termination // index of myInts USB - Original: Gavin Smith
char str3[] = "Arduino"; myInts[6] = 12; // ERROR! Indexes BATT DC DC I2C - www.e2cre8.be >> Brainbox AVR
char str4[8] = "Arduino"; // are 0 though 5 4x AA MOTOR MOTOR (LCD, US, …)
L R

You might also like