Scrolling message.

This commit is contained in:
Andreas Fried 2019-01-06 01:24:11 +01:00
parent d9589b49de
commit e545e50462
2 changed files with 45 additions and 14 deletions

View file

@ -17,7 +17,7 @@ const uint8_t font_5x7_col[128][5] PROGMEM = {
{ 0x10, 0x18, 0x1C, 0x18, 0x10 }, //
{ 0x00, 0x3E, 0x1C, 0x08, 0x00 }, //
{ 0x00, 0x08, 0x1C, 0x3E, 0x00 }, //
{ 0x04, 0x0C, 0x1C, 0x0C, 0x04 }, //
{ 0x02, 0x55, 0x15, 0x55, 0x0F }, // (ä)
{ 0x7F, 0x00, 0x00, 0x00, 0x00 }, // (1 col left)
{ 0x7F, 0x7F, 0x00, 0x00, 0x00 }, // (2 col left)
{ 0x7F, 0x7F, 0x7F, 0x00, 0x00 }, // (3 col left)

View file

@ -19,32 +19,51 @@ void shiftout(uint8_t bit)
PORTB = 0;
}
uint8_t buffer[120];
void write_letter_at(int startcol, uint8_t letter) {
for (int8_t x = 0; x < 5; x++) {
if (startcol + x >= 0 && startcol + x < width) {
buffer[startcol + x] = pgm_read_byte_near(&font_5x7_col[letter][x]);
}
}
}
void setup()
{
for (uint8_t i = 2; i <= 10; i++) {
pinMode(i, OUTPUT);
}
pinMode(13, OUTPUT);
write_letter_at(0, 'H');
write_letter_at(6, 'i');
write_letter_at(12, '!');
}
char *message = "Hello world! ";
const char *message = "N\x0f""chster Halt: Kronenplatz";
void letters(int round) {
for (int i = 0; i < width; i++) {
buffer[i] = 0;
}
int pos = 0;
for (unsigned c = 0; c < strlen(message); c++) {
write_letter_at(round + pos, message[c]);
pos += 6;
}
}
int ticks = 0;
int runde = 120;
void loop()
{
for (uint8_t y = 0; y < lines; y++) {
uint8_t letter = 0;
uint8_t lettercol = 0;
for (uint8_t x = 0; x < width; x++) {
if (lettercol == 5) {
lettercol = 0;
letter++;
shiftout(0);
} else {
uint8_t col = pgm_read_byte_near(&font_5x7_col[message[letter]][lettercol]);
uint8_t bit = (col & (1 << y)) ? 1 : 0;
shiftout(bit);
lettercol++;
}
uint8_t bit = (buffer[x] & (1 << y)) ? 1 : 0;
shiftout(bit);
}
digitalWrite(13, 1);
@ -53,4 +72,16 @@ void loop()
digitalWrite(13, 0);
digitalWrite(line_pins[y], 0);
}
ticks++;
if (ticks == 8) {
ticks = 0;
runde--;
letters(runde);
if (runde == -(6 * (int)strlen(message))) {
runde = 120;
}
}
}