Arduino Cheat Sheet: Structure Digital I/O Data Types
Arduino Cheat Sheet: Structure Digital I/O Data Types
Structure
void setup()
{
void loop()
{
Comments
// this is a single line
/* this is
a multiline */
Setup
pinMode(pin, [INPUT \ OUTPUT \ INPUT_PULLUP]);
Digital I/O
digitalWrite(pin, val);
Analog I/O
analogWrite(pin, val);
Advanced I/O
tone(pin, freq);
noTone(pin);
Control Structures
if(condition)
{
Time
delay(time_ms);
}
else
{
delayMicroseconds(time_us);
// otherwise, do this
millis();
micros();
Data Types
void
//
boolean //
char
//
byte
//
int
//
long
/*
float
RedBoard:
nothing is returned
0, 1, false, true
8 bits: ASCII character
8 bits: 0 to 255, unsigned
16 bits: 32,768 to 32,767, signed
32 bits: 2,147,483,648
to 2,147,483,647, signed */
// 32 bits, signed decimal
Power In
USB to Computer
Reset
Constants
HIGH \ LOW
INPUT \ OUTPUT
true \ false
Mathematical Operators
= // assignment
+ // addition
- // subtraction
* // multiplication
/ // division
% // modulus
Logical Operators
== // boolean equal to
!= // not equal to
< // less than
> // greater than
<= // less than or equal to
>= // greater than or equal to
&& // Boolean AND
|| // Boolean OR
! // Boolean NOT
Bitwise Operators
& // bitwise AND
| // bitwise OR
^ // bitwise XOR
~ // bitwise INVERT
var << n // bitwise shift left by n bits
var >> n // bitwise shift right by n bits
SCL/SDA
(I2C Bus)
Power
5V / 3.3 / GND
Digital I/O
PWM(3,5,6,9,10,11)
Analog
Inputs
ATmega328
Microcontroller
RGB LED
Switch Button
Vibe Motor
LEDs
(Light Emitting Diodes)
Libraries
#include <libraryname.h>
ATmega328
Microcontroller
Buzzer/
Speaker
Light
Sensor
Temperature
Sensor