1 of 9

Lesson 4

Coding on Arduino

2 of 9

Arduino Coding (C++) Basics

Syntax

If/Else Statements

For/While Loops

Functions

Libraries

Data Types

3 of 9

If/Else Statements

if (condition1) {

task1();

} else if (condition2) {

task2();

} else {

task3();

}

4 of 9

For Loop

for (value = initialization; condition1; increment) {

task1();

}

‘increment’ is typically ‘value + n’ where n is some integer. For n = 1, use ‘value++’

5 of 9

While Loop

while (condition2) {

task2();

}

6 of 9

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.

7 of 9

Data Types (each is hyperlinked to an in-depth description)

String (variable) = value

int variable = value

float variable = value

The rest are defined like int and float: type var = val

bool

byte

char

double

array

8 of 9

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)

9 of 9

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.