Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Arduino Cheat Sheet: Main Concepts, Cheat Sheet of Software Engineering

In this cheat sheet you find the main concepts on Arduino open-source electronics platform

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

ehaab
ehaab 🇺🇸

4.2

(32)

275 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1

Partial preview of the text

Download Arduino Cheat Sheet: Main Concepts and more Cheat Sheet Software Engineering in PDF only on Docsity!

ARDUINO CHEAT SHEET Content for this Cheat Sheet provided by Gavin from Robots and Dinosaurs. For more information visit: http://arduino.cc/en/Reference/Extended Structure void setup() void loop() Control Structures if (x<5){ } else {} switch (myvar) { case 1: break; case 2: break; default: } for (int i=0; i <= 255; i++){} while (x<5){ } do {} while (x<5); continue; //Go to next in do/for/while loop return x; // Or ‘return;’ for voids. goto // considered harmful :-) Further Syntax // (single line comment) /* (multi-line comment) */ #define DOZEN 12 //Not baker's! #include General Operators = (assignment operator) + (addition) - (subtraction) * (multiplication) / (division) % (modulo) == (equal to) != (not equal to) < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal to) && (and) || (or) ! (not) Pointer Access & reference operator * dereference operator Bitwise Operators & (bitwise and) | (bitwise or) 4 (bitwise xor) ~ (bitwise not) << (bitshift left) >> (bitshift right) Compound Operators ++ (increment) -- (decrement) += (compound addition) (compound subtraction) (compound multiplication) /= (compound division) &= (compound bitwise and) |= (compound bitwise or) Constants HIGH | LOW INPUT | OUTPUT true | false 143 // Decimal number 0173 // Octal number 0b11011111 //Binary 0x7B // Hex number 7U // Force unsigned 10L // Force long 15UL // Force long unsigned 10.0 // Forces floating point 2.4e5 // 240000 Data Types void boolean (0, 1, false, true) char (e.g. ‘a’ -128 to 127) unsigned char (0 to 255) byte (0 to 255) int (-32,768 to 32,767) unsigned int (0 to 65535) word (0 to 655word (0 to 65535) long (-2,147,483,648 to 2,147,483,647) unsigned long (0 to 4,294,967,295) float (-3.4028235E+38 to 3.4028235E+38) double (currently same as float) sizeof(myint) // returns 2 bytes Strings char S1[15]; char S2/[8]={'a' char S3/[8]={'a','r','d','u','i','n', //\ncluded \O null termination char S4{ ] = "arduino"; char S5[8] char S6[15] = Arrays int myints[6]; int myPins[] = {2, 4, 8, 3, 6}; int mySensVals[6] = {2, 4, -8, 3, 2}; Conversion char() — byte() int() ‘word() long() _ float() Qualifiers static // persists between calls volatile // use RAM (nice for ISR) const // make read-only PROGMEM // use flash Digital VO pinMode(pin, [INPUT,QUTPUT]) digitalWrite(pin, value) int digitalRead(pin) /N\rite High to inputs to use pull-up res Analog /O analogReference([DEFAULT, INTERNAL,EXTERNAL]) int analogRead(pin) //Call twice if ‘switching pins from high Z source. analogWrite(pin, value) // PWM. Advanced /O tone(pin, freqhz) tone(pin, freqhz ,duration_ms) noTone(pin) shiftOut(dataPin, clockPin, [MSBFIRST,LSBFIRST], value) unsigned long pulseln(pin,[HIGH,LOW)) Time unsigned long millis() // 50 days overflow. unsigned long micros() // 70 min overflow delay(ms) delayMicroseconds(us) Math min(x, y) max(x, y) abs(x) constrain(x, minval, maxval) map(val, fromL, fromH, toL, toH) pow(base, exponent) sqrt(x) ‘sin(rad) cos(rad) tan(rad) Random Numbers randomSeed(seed) // Long or int long random(max) long random(min, max) Bits and Bytes lowByte() highByte() bitRead(x,bitn) bitWrite(x,bitn, bit) bitSet(x,bitn) bitClear(x,bitn) bit(bitn) //bitn: O-LSB 7-MSB. External Interrupts attachinterrupt(interrupt, function, [LOW,CHANGE, RISING, FALLING]) detachinterrupt(interrupt) interrupts() nointerrupts() Serial. begin([300, 1200, 2400, 4800, 9600,14400, 19200, 28800, 38400, 57600,115200]}) end() int available() int read() flush() print() printin() write() EEPROM (#include ) byte read(intAddr) write(intAddr,myByte) Servo (#include ) attach(pin , [min_uS, max_uS]) write(angle) // 0-180 writeMicroseconds(uS) //1000- 2000,1500 is midpoint read() // 0-180 attached() //Returns boolean detach() SoftwareSerial(RxPin,TxPin) // #include begin(longSpeed) // up to 9600 char read() // blocks till data print(myData) or printin(myData) Wire (#include ) // For 120 begin() // Join as master begin(addr) // Join as slave @ addr requestFrom(address, count) beginTransmission(addr) // Step 1 send(mybyte) // Step 2 ‘send(char * mystring) send(byte * data, size) endTransmission() // Step 3 byte available() // Num of bytes byte receive() //Return next byte onReceive(handler) onRequest(handler) ‘ATMega168 | ATMega328 | ATMega280 Flash (2k for corres sams 2a SRAM | 1K 28 exe EEPROM 5128 1K 8 Duemitanover Nano/ Pro/ Mega Frown 14+ 6andop sy y yeaa #otl0 (Nano has 14 +8) S416 analog o-RXI 1-71 sete! Ping | 0°8X 19-AX2 18-12 1K 17-8xS 16-136 1S-Axe 14-14 2 rio) 23,21,20,9,8 Ext Interrupts | (int 1) (RQ0™- IFS) PWM Pins 0-19 38S : 51 MOS! spt 12-MISO- 50-MISO 18-ScK 52-S0K wo ‘Analogs “SDA |20= SDA Analogs -Sck _|21 Sct es ia elo so EFS] @ woe nsenped "spo || 38 SFE] oe es (faD}Poo2 Besriscy (0) ots exraigiease7Blpos qos oraLieros Beas 6 q s mons ‘Amogetwanen28 Arauino reser] 09" rxo bor og Bee q moa bog git isco oor (wm) 008 he] gis isp oo%0 qu doe 86 SO |S Head 0-0 arduino.ce