Arduino Programming
Arduino IDE
(Integrated Developer Environment)
Download from www.Arduino.cc
Allows you to:
Variables
Problem:
How big is the information?
How much memory must be allocated?
What type of variable?
Data is Stored in memory with Bits
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
^ One Byte ^
Reading Binary Numbers:
N = 0 1 2 3 4 5 6 7
1 + 8 + 16 + 32 + 128
= 185
1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255
N = 0 1 2 3 4 5 6 +/-
1 + 2 + 4 + 8 + 16 + 32 + 64 x +/-
= [-128, 127]
Unsigned Bytes
Signed Bytes
The Arduino must know the data type!
Some examples:
^often depends on processor^
Arrays
value = variable[n];
n = 0 1 2 3 4
Buffer overflow:
number = numbers[100];
Char:
ASCII Table:
String:
Booleans
The Compiler:
Great for checking mistakes!
Declaring v.s. Defining
Declaration
Definition
Initialize
void setup()
void loop()
Built-in functions
If - else if - Else statement
While loop
For loop
Break & continue
Switch… case
Functions
Global Variables
Local Variables
Analog
Libraries
TinkerCad challenge:
GOAL:
Read 2 potentiometers as analog in values (A0-A5 pins) and print their mapped data (from a value 0-1023 to 0-180) to the lcd display every x milliseconds.
Use functions!
Useful built-in functions:
TinkerCad Challenge Answer:
Structures
Cars
Brand
Price
Color
Car: Roadster
Car: Prius
Pointers
I2C (I2C) Protocol
PWM protocol
SPI protocol
PWM protocol
SPI protocol