Skip to content

Instantly share code, notes, and snippets.

@aron-bordin
Created February 12, 2015 13:22
Show Gist options
  • Save aron-bordin/b5fe9dacf8c0e17d81d0 to your computer and use it in GitHub Desktop.
Save aron-bordin/b5fe9dacf8c0e17d81d0 to your computer and use it in GitHub Desktop.
Example on how to show a list of letters with LED matrix on Arduino
#include "TimerObject.h"
#include "LedMatrixObject.h"
TimerObject *timer = new TimerObject(1000); //change letter each second
LedMatrixObject *led = new LedMatrixObject(2, 3, 4, 5, 6, 7, 8, 9);
int letterId = 0; //you can set a number to represent each leter. You check this number on loop()
int letterList[] = {0, 4, 2, 10}; //list of letters in order
void setup(){
timer->Start();
timer->setOnTimer(&updateLetter);
}
void updateLetter(){
//here you update your letters by id
//this function will be called each second
//so we check the letterID and update its value to the next letter
for(int i = 0; i < 4; i++){ //update this line. 4 is the size of the word
if(letterList[i] == letterId && i < 3){ //if this is the displayed letter
letterId = letterList[i+1]; //get the next letter
}
if(i == 3){//update this line. 3 is the size of the word - 1
letterId = letterList[0]; //return to the fist letter
}
}
}
void loop(){
timer->Update(); //run the timer. Each 1 second will call the updateLetter() and modify letterID
switch (letterId) {
case 0:
led->setScene(A);
break;
case 1:
led->setScene(B);
break;
case 2:
led->setScene(C);
break;
//add a case to each necessary letter
}
led->draw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment