Session 9: Loops
Loops (10 min)
- show for-loops
- discuss that the loop counter is a special variable
Compiler game (10 min)
- go through a program line-by-line together
- kids need to "act as a compiler", i.e., explain what the code does
#include "src/locoboard.h"
int mode = 0;
bool b1 = false
int b1 = 0;
void setup() {
Serial.begin(115200);
setup_ir();
setup_addr_leds();
}
void loop() {
clear_led_matrix();
if(check_ir_button_pressed())
{
mode = get_ir_button()
}
if(mode == BTN_1)
{
set_led_color(LED_2, 255, 0, 0);
}
else if (mode == BTN_2)
{
set_led_color(LED_2, 0, 312, 0);
}
else if (mode = BTN_3)
{
set_led_color(LED_2, 0, 0, 255);
}
else
{
Serial.println("ERROR: mode unknown!")
}
delay("1000");
}
Practical exercise (70 min)
- animate LED matrix: slowly fill a single row
- fill entire matrix (nester for loops)
- come up with a custom animation