Italo, sua dica foi primordial. Mas o software ainda nao ficou legal não, to achando meio complicado, preciso pensar direitinho como fazer para manter um valor por um tempo, e mudar num outro tempo. Nao pode haver interrupção do loop, se não o matrix fica desligado. ô falta faz um thread
Segue o código, vou tentar melhora-lo e posto outro em seguida. To pensando em aproveitar pra fazer minha primeira lib
long lastDisplayChange = 0;
int changeCount = 0;
const int row[2] = { 9, 10 };
const int col[2] = { 6, 7 };
int pixels[2][2] = {
{HIGH, HIGH},
{HIGH, HIGH}
};
void setup()
{
Serial.begin(9600);
// Inicializa as portas/leds
for (int thisPin = 0; thisPin < 2; thisPin++)
{
// initialize the output pins:
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);
// turn all off
digitalWrite(col[thisPin], HIGH);
}
// Mostra a inicializacao
Serial.println("Started");
}
void loop()
{
if ((millis() - lastDisplayChange) > 600)
{
lastDisplayChange = millis();
changeCount++;
if(changeCount > 2)
{
changeCount = 0;;
}
}
switch(changeCount)
{
case 0:
pixels[0][0] = LOW; pixels[0][1] = HIGH;
pixels[1][0] = HIGH; pixels[1][1] = HIGH;
break;
case 1:
pixels[0][0] = HIGH; pixels[0][1] = LOW;
pixels[1][0] = LOW; pixels[1][1] = HIGH;
break;
case 2:
pixels[0][0] = HIGH; pixels[0][1] = HIGH;
pixels[1][0] = HIGH; pixels[1][1] = LOW;
break;
}
refreshScreen();
}
void refreshScreen() {
// iterate over the rows (anodes):
for (int thisRow = 0; thisRow < 2; thisRow++) {
// take the row pin (anode) high:
digitalWrite(row[thisRow], HIGH);
// iterate over the cols (cathodes):
for (int thisCol = 0; thisCol < 2; thisCol++) {
// get the state of the current pixel;
int thisPixel = pixels[thisRow][thisCol];
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(col[thisCol], thisPixel);
// turn the pixel off:
if (thisPixel == LOW) {
digitalWrite(col[thisCol], HIGH);
}
}
// take the row pin low to turn off the whole row:
digitalWrite(row[thisRow], LOW);
}
}