Created
June 8, 2021 16:58
-
-
Save tuna-f1sh/bbd27313f8491467f17f54a18e84cf36 to your computer and use it in GitHub Desktop.
Hanover FlipDot Display Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include <Wire.h> | |
#define COLS 96 | |
#define ROWS 16 | |
#define FRAME_SIZE ((ROWS * COLS) / 8) | |
#define COL_BYTES FRAME_SIZE / 8 | |
#define FOOTER_CHAR 0x03 | |
#define DATA_SIZE FRAME_SIZE * 2 | |
#define BUFFER_SIZE 5 + DATA_SIZE + 3 | |
#define MASTER_EN 9 | |
uint8_t header[] = | |
{ 0x02, | |
0x31, // 0 = Text, 1 = Graphics | |
0x38, // Display Address (8 by default) | |
0x00, // Resolution Data | |
0x00, // Resolution Data | |
}; | |
uint8_t data[DATA_SIZE] = {0x00}; | |
uint8_t buffer[BUFFER_SIZE] = {0x00}; | |
void byte_to_ascii(uint8_t b, uint8_t *twob) { | |
uint8_t b1 = 0; | |
uint8_t b2 = 0; | |
b1 = b >> 4; | |
if (b1 > 9) | |
b1 += 0x37; | |
else | |
b1 += 0x30; | |
b2 = b % 16; | |
if (b2 > 9) | |
b2 += 0x37; | |
else | |
b2 += 0x30; | |
twob[0] = b1; | |
twob[1] = b2; | |
} | |
uint8_t calc_crc(uint8_t *buffer, size_t len) { | |
uint8_t sum = 0; | |
for (int i = 0; i < len; i++) { | |
sum += buffer[i]; | |
} | |
return ((sum ^ 0xFF) + 1); | |
} | |
void setup() { | |
pinMode(MASTER_EN, OUTPUT); | |
Serial.begin(4800); | |
} | |
void loop() { | |
uint8_t crc_b = 0; | |
uint8_t resolution[2]; | |
uint8_t byte_ascii_buffer[2]; | |
byte_to_ascii(FRAME_SIZE & 0xFF, &header[3]); | |
buffer[BUFFER_SIZE - 3] = FOOTER_CHAR; | |
for (int j = 0; j <= 16; j++) { | |
// calculate byte as two ascii values for address | |
byte_to_ascii(j, byte_ascii_buffer); | |
header[2] = byte_ascii_buffer[1]; | |
// copy into send buffer | |
memcpy(buffer, header, 5); | |
digitalWrite(MASTER_EN, HIGH); | |
// set all to on | |
memset(&buffer[5], 'F', DATA_SIZE); | |
crc_b = calc_crc(buffer, BUFFER_SIZE - 2); // -2 for CRC bytes | |
byte_to_ascii(crc_b, &buffer[BUFFER_SIZE - 2]); // set last two bytes to CRC | |
Serial.write(buffer, sizeof(buffer)); | |
delay(500); | |
// set all to off | |
memset(&buffer[5], '0', DATA_SIZE); | |
crc_b = calc_crc(buffer, BUFFER_SIZE - 2); // -2 for CRC bytes | |
byte_to_ascii(crc_b, &buffer[BUFFER_SIZE - 2]); | |
Serial.write(buffer, sizeof(buffer)); | |
delay(500); | |
digitalWrite(MASTER_EN, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment