Lesson 4
Coding on Arduino
Arduino Coding (C++) Basics
Syntax
If/Else Statements
For/While Loops
Functions
Libraries
Data Types
If/Else Statements
if (condition1) {
task1();
} else if (condition2) {
task2();
} else {
task3();
}
For Loop
for (value = initialization; condition1; increment) {
task1();
}
‘increment’ is typically ‘value + n’ where n is some integer. For n = 1, use ‘value++’
While Loop
while (condition2) {
task2();
}
Libraries
#include <library.h>
Includes outside libraries in your sketch. This gives the programmer access to a large group of standard C libraries (groups of pre-made functions), and also libraries written especially for Arduino.
#define constant newValue
Allows the programmer to give a name to a constant value before the program is compiled. Defined constants in arduino don’t take up any program memory space on the chip. The compiler will replace references to these constants with the defined value at compile time.
Data Types (each is hyperlinked to an in-depth description)
Our Code
Uses FastLED library to assign a matrix of values to the LEDs
Use these matrix of values to spell out the time
Build structures to set colors & animations for LEDs with FastLED library
Control which animations the clock displays via button functions
Use LDR to set relative brightness of LEDs
(Download the Arduino IDE here)
Your Task
Use the incomplete Word Clock code to make more functions that spell out each time and an updateTime() to put all this together and display the current time on the Word Clock. You will need the clock face as a reference —>
Optional: Add new animations to toggle with the animation button.