code cleanup
This commit is contained in:
parent
79b13cb100
commit
beac9ae2f5
1 changed files with 56 additions and 53 deletions
85
src/main.cpp
85
src/main.cpp
|
@ -4,53 +4,58 @@
|
||||||
|
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
|
||||||
const int width = 120;
|
const int WIDTH = 120;
|
||||||
const int lines = 7;
|
const int LINES = 7;
|
||||||
|
const int LINE_PINS[7] = { 2, 3, 4, 5, 6, 7, 8 };
|
||||||
|
|
||||||
const int line_pins[7] = { 2, 3, 4, 5, 6, 7, 8 };
|
uint8_t buffer[120];
|
||||||
|
String message = "9600N1 ISO8859-15 https://github.com/silentium83/zielanzeige/tree/develop";
|
||||||
|
String newMessage;
|
||||||
|
int ticks = 0;
|
||||||
|
int runde = 120;
|
||||||
|
|
||||||
// Shift register needs to use raw AVR
|
// Shift register needs to use raw AVR
|
||||||
// B1 is clock
|
// B1 is clock
|
||||||
// B2 is data
|
// B2 is data
|
||||||
void shiftout(uint8_t bit)
|
void shiftout(uint8_t bit) {
|
||||||
{
|
|
||||||
PORTB = bit << 2;
|
PORTB = bit << 2;
|
||||||
PORTB |= 0x02;
|
PORTB |= 0x02;
|
||||||
PORTB = 0;
|
PORTB = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t buffer[120];
|
|
||||||
String message = "ISO8859-15 9600N1 https://github.com/silentium83/zielanzeige/tree/develop";
|
|
||||||
String newMessage;
|
|
||||||
int ticks = 0;
|
|
||||||
int runde = 120;
|
|
||||||
|
|
||||||
void write_letter_at(int startcol, uint8_t letter) {
|
void write_letter_at(int startcol, uint8_t letter) {
|
||||||
for (int8_t x = 0; x < 5; x++) {
|
for (int_fast8_t x = 0; x < 5; x++) {
|
||||||
if (startcol + x >= 0 && startcol + x < width) {
|
int col = startcol + x;
|
||||||
buffer[startcol + x] = pgm_read_byte_near(&font_5x7_col[letter][x]);
|
if (col >= 0 && col < WIDTH) {
|
||||||
|
buffer[col] = pgm_read_byte(&font_5x7_col[letter][x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void letters(int round) {
|
||||||
{
|
for (int i = 0; i < WIDTH; i++) {
|
||||||
for (uint8_t i = 2; i <= 10; i++) {
|
buffer[i] = 0;
|
||||||
pinMode(i, OUTPUT);
|
|
||||||
}
|
}
|
||||||
pinMode(13, OUTPUT);
|
|
||||||
|
|
||||||
write_letter_at(0, 'H');
|
int pos = 0;
|
||||||
write_letter_at(6, 'i');
|
for (unsigned int c = 0; c < message.length(); c++) {
|
||||||
write_letter_at(12, '!');
|
write_letter_at(round + pos, message[c]);
|
||||||
|
pos += 6;
|
||||||
Serial.begin(9600);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void receive_serial() {
|
void receive_serial() {
|
||||||
if (Serial.available() > 0) {
|
while (Serial.available() > 0) {
|
||||||
char receivedChar = Serial.read();
|
char receivedChar = Serial.read();
|
||||||
if (receivedChar == '\n') {
|
switch (receivedChar) {
|
||||||
|
case '\b': // backspace
|
||||||
|
if (newMessage.length() > 0) {
|
||||||
|
newMessage.remove(newMessage.length() - 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '\n': // newline
|
||||||
|
case '\r': // carriage return
|
||||||
|
if (newMessage.length() > 0) {
|
||||||
if (message != newMessage) {
|
if (message != newMessage) {
|
||||||
message = newMessage;
|
message = newMessage;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
|
@ -58,37 +63,35 @@ void receive_serial() {
|
||||||
}
|
}
|
||||||
newMessage = "";
|
newMessage = "";
|
||||||
}
|
}
|
||||||
else if (receivedChar != '\r') {
|
break;
|
||||||
|
default:
|
||||||
newMessage += receivedChar;
|
newMessage += receivedChar;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void letters(int round) {
|
void setup() {
|
||||||
for (int i = 0; i < width; i++) {
|
for (uint_fast8_t i = 2; i <= 10; i++) {
|
||||||
buffer[i] = 0;
|
pinMode(i, OUTPUT);
|
||||||
}
|
}
|
||||||
|
pinMode(13, OUTPUT);
|
||||||
|
|
||||||
int pos = 0;
|
Serial.begin(9600);
|
||||||
for (unsigned c = 0; c < message.length(); c++) {
|
|
||||||
write_letter_at(round + pos, message[c]);
|
|
||||||
pos += 6;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop() {
|
||||||
{
|
for (uint_fast8_t y = 0; y < LINES; y++) {
|
||||||
for (uint8_t y = 0; y < lines; y++) {
|
for (uint_fast8_t x = 0; x < WIDTH; x++) {
|
||||||
for (uint8_t x = 0; x < width; x++) {
|
|
||||||
uint8_t bit = (buffer[x] & (1 << y)) ? 1 : 0;
|
uint8_t bit = (buffer[x] & (1 << y)) ? 1 : 0;
|
||||||
shiftout(bit);
|
shiftout(bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
digitalWrite(13, 1);
|
digitalWrite(13, 1);
|
||||||
digitalWrite(line_pins[y], 1);
|
digitalWrite(LINE_PINS[y], 1);
|
||||||
delayMicroseconds(200);
|
delayMicroseconds(200);
|
||||||
digitalWrite(13, 0);
|
digitalWrite(13, 0);
|
||||||
digitalWrite(line_pins[y], 0);
|
digitalWrite(LINE_PINS[y], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ticks++;
|
ticks++;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue