Arduino Programming Cheat Sheet Structure & Flow Basic Program Structure void setup() { // Runs once when sketch starts } void loop() { // Runs repeatedly } Control Structures if (x < 5) { ... } else { ... } while (x < 5) { ... } for (int i = 0; i < 10; i++) { ... } // Exit a loop immediately break; continue; // Go to next iteration switch (var) { case 1: ... break; case 2: ... break; default: ... } return x; // x must match return type return; // For void return type Function Definitions () { ... } e.g. int double(int x) {return x*2;}

Operators

Primary source: Arduino Language Reference https://arduino.cc/en/Reference/

Built-in Functions

Libraries

General Operators = assignment + add subtract * multiply / divide % modulo == equal to != not equal to < less than > greater than <= less than or equal to >= greater than or equal to && and || or ! not

Pin Input/Output Digital I/O - pins 0-13 A0-A5 pinMode(pin, [INPUT, OUTPUT, INPUT_PULLUP]) int digitalRead(pin) digitalWrite(pin, [HIGH, LOW])

Math min(x, y) max(x, y) abs(x) sin(rad) cos(rad) tan(rad) sqrt(x) pow(base, exponent) constrain(x, minval, maxval) map(val, fromL, fromH, toL, toH)

Analog In - pins A0-A5 int analogRead(pin) analogReference( [DEFAULT, INTERNAL, EXTERNAL])

Random Numbers randomSeed(seed) // long or int long random(max) // 0 to max-1 long random(min, max)

Serial - comm. with PC or via RX/TX begin(long speed) // Up to 115200 end() int available() // #bytes available int read() // -1 if none available int peek() // Read w/o removing flush() print(data) println(data) write(byte) write(char * string) write(byte * data, size) SerialEvent() // Called if data rdy

Compound Operators ++ increment -- decrement += compound addition -= compound subtraction *= compound multiplication /= compound division &= compound bitwise and |= compound bitwise or

PWM Out - pins 3 5 6 9 10 11 analogWrite(pin, value)

Bits and Bytes lowByte(x) highByte(x) bitRead(x, bitn) bitWrite(x, bitn, bit) bitSet(x, bitn) bitClear(x, bitn) bit(bitn) // bitn: 0=LSB 7=MSB

SoftwareSerial.h - comm. on any pin SoftwareSerial(rxPin, txPin) begin(long speed) // Up to 115200 listen() // Only 1 can listen isListening() // at a time. read, peek, print, println, write // Equivalent to Serial library

Type Conversions char(val) byte(val) int(val) word(val) long(val) float(val)

EEPROM.h - access non-volatile memory byte read(addr) write(addr, byte) EEPROM[index] // Access as array

Bitwise Operators & bitwise and ^ bitwise xor << shift left

| ~ >>

bitwise or bitwise not shift right

Pointer Access & reference: get a pointer * dereference: follow a pointer

Advanced I/O tone(pin, freq_Hz) tone(pin, freq_Hz, duration_ms) noTone(pin) shiftOut(dataPin, clockPin, [MSBFIRST, LSBFIRST], value) unsigned long pulseIn(pin, [HIGH, LOW]) Time unsigned long millis() // Overflows at 50 days unsigned long micros() // Overflows at 70 minutes delay(msec) delayMicroseconds(usec)

External Interrupts attachInterrupt(interrupt, func, [LOW, CHANGE, RISING, FALLING]) detachInterrupt(interrupt) interrupts() noInterrupts()

7 ~6 ~5 4 ~3 2 TX→1 RX←0

AREF GND 13 12 ~11 ~10 ~9 8

DIGITAL (PWM~)

L TX RX

ARDUINO UNO ON ICSP 1

persists between calls in RAM (nice for ISR) read-only in flash

ATmega382: 16MHz, 32KB Flash (program), 2KB SRAM, 1KB EEPROM

DC in sugg. 7-12V limit 6-20V

POWER

ANALOG IN

SDA SCL

Arrays int myPins[] = {2, 4, 8, 3, 6}; // Array of 6 ints int myInts[6]; myInts[0] = 42; // Assigning first // index of myInts myInts[6] = 12; // ERROR! Indexes // are 0 though 5

Wire.h - I²C communication begin() // Join a master begin(addr) // Join a slave @ addr requestFrom(address, count) beginTransmission(addr) // Step 1 send(byte) // Step 2 send(char * string) send(byte * data, size) endTransmission() // Step 3 int available() // #bytes available byte receive() // Get next byte onReceive(handler) onRequest(handler)

WWW.ARDUINO.CC - Made in Italy

A0 A1 A2 A3 A4 A5

Qualifiers static volatile const PROGMEM

RESET

IOREF RESET 3.3V 5V GND GND Vin

Strings char str1[8] = {'A','r','d','u','i','n','o','\0'}; // Includes \0 null termination char str2[8] = {'A','r','d','u','i','n','o'}; // Compiler adds null termination char str3[] = "Arduino"; char str4[8] = "Arduino";

Numeric Constants 123 decimal 0b01111011 binary 0173 octal - base 8 0x7B hexadecimal - base 16 123U force unsigned 123L force long 123UL force unsigned long 123.0 force floating point 1.23e6 1.23*10^6 = 1230000

SCL SDA

Data Types boolean true | false char -128 - 127, 'a' '$' etc. unsigned char 0 - 255 byte 0 - 255 int -32768 - 32767 unsigned int 0 - 65535 word 0 - 65535 long -2147483648 - 2147483647 unsigned long 0 - 4294967295 float -3.4028e+38 - 3.4028e+38 double currently same as float void i.e., no return value

int1 int0

Variables, Arrays, and Data

Servo.h - control servo motors attach(pin, [min_uS, max_uS]) write(angle) // 0 to 180 writeMicroseconds(uS) // 1000-2000; 1500 is midpoint int read() // 0 to 180 bool attached() detach()

by Mark Liffiton version: 2017-04-10 source: h�ps://github.com/liffiton/Arduino-Cheat-Sheet/

Adapted from: - Original: Gavin Smith - SVG version: Frederic Dufourg - Arduino board drawing: Fritzing.org

arduino uno - electrician.wz.cz

DIGITAL (PWM~). AREF. GND1312 11 109 8. 765 43 2. TX→1 RX←0. L. TX. RX. POWER. ANALOG IN. A0A1A2A3A4A5. IOREF RESET 3.3V 5VGND GND Vin. ON. WWW.ARDUINO.CC - Made in Italy. RESET. ICSP. 1 ... EEPROM.h - access non-volatile memory byte read(addr) write(addr, byte). EEPROM[index] // Access ...

101KB Sizes 1 Downloads 313 Views

Recommend Documents

Arduino Uno and Race Coordinator.pdf
Page 1 of 1. Page 1. Arduino Uno and Race Coordinator.pdf. Arduino Uno and Race Coordinator.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Arduino Uno and Race Coordinator.pdf. Page 1 of 1.

Arduino Uno and Race Coordinator.pdf
stop false triggering due to noise. Page 3 of 4. Arduino Uno and Race Coordinator.pdf. Arduino Uno and Race Coordinator.pdf. Open. Extract. Open with. Sign In.

UNO Template
Jul 8, 2015 - Free float is small at just under 40% of market cap;. Continued on page 2. Research Analysts ... If we adjust for free float, this is even smaller (at most, 45% of. GDP);. □ After the 1987 crash, the US savings ratio ..... all the com

UNO Template
Jul 31, 2014 - For Australian and New Zealand stocks, 12-month rolling yield is ... Credit Suisse policy and/or applicable law and regulations preclude certain ...

UNO Template
Jul 12, 2015 - price implies 21x FY17E earnings, but note strong yield support (~4%). ..... a third-party provider to Credit Suisse of research support services. ...... viewed as "advice" within the meaning of Section 975 of the Dodd-Frank Wall ...

UNO Template
Capital goods. Consumer discretionary. Telecom services. REITs. Diversified financials. Banks. Consumer staples. Health care. Transportation. Real estate. -1.5%. -1.0%. -0.5%. 0.0% ...... Credit Suisse has managed or co-managed a public offering of s

tia uno um.pdf
... Heaton wherever they have been reborn. Page 4 of 8. tia uno um.pdf. tia uno um.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying tia uno um.pdf.

UNO Template - Credit Suisse | PLUS
May 18, 2015 - management buying a large-sized company in distress and turning it around .... has become the major customer accounting for 45% of Motherson's revenues. ... manufacturer of automotive modules specialising in high quality ...

UNO Template -
Hancock Alpha. West (Alpha west coal project). GVK Galilee ...... It is also looking to sell stake in its tower business and enter spectrum sharing contracts with ...

UNO Template
stellar asset quality performance seen during the 2005–09 cycle. □ DBS remains our top pick—lower earnings risks + ...... The Global Industry Classification Standard (GICS) was developed by and is the exclusive property of Morgan Stanley Capita

UNO Template -
Number"). To be perfectly clear, this is not a criticism, GILD's strategy of front running HCV patients at a lower price is likely the best strategy given the current scenario. …continued on the next page… Share price ... *Stock ratings are relat

UNO Template
Feb 1, 2014 - Client-Driven Solutions, Insights, and Access. 06 January 2014. Asia Pacific/ ..... Beschizza, Director of Operations, has been in the natural rubber and agricultural industry for about 40 years. Mr James .... 197 acres of planted oil p

UNO Template -
to Credit Suisse's Policies for Managing Conflicts of Interest in connection with Investment Research: ... The turnaround could also suffer if vendors cut terms or ...

tia uno um.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. tia uno um.pdf.

CT-UNO Schematic.pdf
و [OA] و OB]] شعاعان للدائرة .(C). الزاوية BÔAتسمى الزاوية المركزية. حدد زوايا مركزية أخرى في هذا الشكل . o. C. A. D. B. O. التي تحصر القوس AB. #. Whoops! There was a

UNO DE ENERO.pdf
There was a problem loading more pages. Retrying... UNO DE ENERO.pdf. UNO DE ENERO.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying UNO ...

Capitulo Uno COFA +13.pdf
mientras)consumieras)por)lo)menos)un)café)en)intervalos)de)media)hora.)También). servían)lo)que)alguna)vez)fue)su)Pierogi)y)Borscht)vegetariano)favorito ...

gimp-grupo-uno-de-practicas.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item.

Board KIM Uno Sep2014.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Board KIM Uno ...