LEDDisplay/display/display.ino

90 lines
2.3 KiB
C++

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, 2, 1, 16,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG +
NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_ROWS +
NEO_TILE_PROGRESSIVE, NEO_GRB + NEO_KHZ800);
int i=0;
#define NUM_COLORS 7
const PROGMEM uint16_t colors[NUM_COLORS] = {
Adafruit_NeoMatrix::Color(127, 0, 0),
Adafruit_NeoMatrix::Color(0, 127, 0),
Adafruit_NeoMatrix::Color(0, 0, 127),
Adafruit_NeoMatrix::Color(127, 0, 127),
Adafruit_NeoMatrix::Color(127, 127, 0),
Adafruit_NeoMatrix::Color(0, 127, 127),
Adafruit_NeoMatrix::Color(127, 127, 127)
};
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};
byte len = 0;
unsigned char speed;
signed 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();
matrix.setTextSize(1);
matrix.setTextWrap(false);
currColor[0] = colors[random(NUM_COLORS)];
currColor[1] = colors[random(NUM_COLORS)];
setParams(&text[0], "/usr/space", 1000);
setParams(&text[1], "Wir haben offen!", 100);
}
void move(runtext *textstruct, int row){
if(millis()-(textstruct+row)->millis>=(textstruct+row)->speed){
(textstruct+row)->millis=millis();
changed=true;
(textstruct+row)->pos--;
if((textstruct+row)->pos < -(textstruct+row)->len*6){
(textstruct+row)->pos = matrix.width();
currColor[row]=colors[random(NUM_COLORS)];
}
}
}
void loop()
{
if(changed){
matrix.fillScreen(matrix.Color(0, 0, 0));
matrix.setCursor(text[0].pos, 0);
matrix.setTextColor(currColor[0]);
matrix.print(text[0].text);
matrix.setCursor(text[1].pos, 8);
matrix.setTextColor(currColor[1]);
matrix.print(text[1].text);
portDISABLE_INTERRUPTS();
delay(5);
matrix.show();
delay(5);
portENABLE_INTERRUPTS();
changed=false;
}
move(text,0);
move(text,1);
}