Zeitdifferenz via millis() statt delay()

This commit is contained in:
Peter 2020-01-15 20:18:02 +01:00
parent 40a20fc3be
commit 74a8eaeac6
Signed by: pludi
GPG Key ID: FB1A00FEE77E2C36
1 changed files with 48 additions and 13 deletions

View File

@ -21,6 +21,24 @@ const PROGMEM uint16_t colors[NUM_COLORS] = {
};
uint16_t currColor[2];
typedef struct {
char text[17]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char len = 0;
unsigned char speed;
char pos = 0;
unsigned long millis = 0;
} runtext;
runtext text[2];
void setParams(runtext *textstruct, char* text, unsigned char speed){
strncpy(textstruct->text, text, 16);
textstruct->len=min((int)strlen(text),16);
textstruct->speed=speed;
}
bool changed=true;
void setup()
{
matrix.begin();
@ -30,26 +48,43 @@ void setup()
Serial.println("Setup Done");
currColor[0] = colors[random(NUM_COLORS)];
currColor[1] = colors[random(NUM_COLORS)];
setParams(&text[0], "/usr/space", 1000);
setParams(&text[1], "Wir haben offen!", 1000);
}
void loop()
{
if(changed){
matrix.fillScreen(matrix.Color(0, 0, 0));
matrix.setCursor(i, 0);
matrix.setCursor(text[0].pos, 0);
matrix.setTextColor(currColor[0]);
matrix.print("/usr/space @36C3");
matrix.print(text[0].text);
matrix.setCursor(text[1].pos, 0);
matrix.setTextColor(currColor[1]);
matrix.setCursor(i*3, 8);
matrix.print("Sticker Exchange Sticker Exchange");
portDISABLE_INTERRUPTS();
delay(1);
matrix.print(text[1].text);
matrix.show();
portENABLE_INTERRUPTS();
if(--i < -16*6) {
i = matrix.width();
currColor[0] = colors[random(NUM_COLORS)];
currColor[1] = colors[random(NUM_COLORS)];
changed=false;
}
if(millis()-text[0].millis>=text[0].speed){
text[0].millis=millis();
changed=true;
text[0].pos--;
if(text[0].pos<-text[0].len*6){
text[0].pos = matrix.width();
currColor[0]=colors[random(NUM_COLORS)];
}
}
if(millis()-text[1].millis>=text[1].speed){
text[1].millis=millis();
changed=true;
text[1].pos--;
if(text[1].pos<-text[1].len*6){
text[1].pos = matrix.width();
currColor[1]=colors[random(NUM_COLORS)];
}
}
delay(249);
}