Skip to content

Session 13: Concurrency

Task

#include "src/locoboard.h"

void animate()
{
  clear_led_matrix();
  for(int i=0; i<8; i++)
  {
    set_led_matrix_pixel(0, i, HIGH);
    show_led_matrix();
    delay(500);
  }
}

void process_ir_input()
{
  if(check_ir_button_pressed())
  {
    if(get_ir_button() == BTN_0)
    {
      Serial.println("Hello, world!");
    }
  }
}

void setup()
{
  Serial.begin(115200);
  setup_ir();
}

void loop()
{
  animate();
  process_ir_input();
}

Reference solution

int i = 0;
long animation_timer = 0;

void animate()
{
  if (i==0) clear_led_matrix();
  if(millis() > animation_timer)
  {
    set_led_matrix_pixel(0, i, HIGH);
    show_led_matrix();
    i++;
    if (i==8) i=0;

    animation_timer = millis() + 500;
  }
}