Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Flip Dot Clock
// 0x80 beginning
//___________________
// 0x81 - 112 bytes / no refresh / C+3E
// 0x82 - refresh
// 0x83 - 28 bytes of data / refresh / 2C
// 0x84 - 28 bytes of data / no refresh / 2C
// 0x85 - 56 bytes of data / refresh / C+E
// 0x86 - 56 bytes of data / no refresh / C+E
// ---------------------------------------
// address or 0xFF for all
// data ... 1 to nuber of data bytes
// 0x8F end
// panel's speed setting: 1-OFF 2-ON 3 - ON
// panel address : 1 (8 pos dip switch: 1:on 2 -8: off)
// I was sng RS485 Breakout and Duemilanova connected in the following way:
// [Panel] [RS485] [Arduino]
// 485+ A
// 485- B
// 3-5V 5V
// RX-I TX
// TX-O Not connected
// RTS 5V
// GND GND
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
// control pin
int txden = 8;
// numbers font
byte zero[] = {B0111110, B0100010, B0100010, B0111110};
byte one[] = {B0111110, B0000000, B0000000, B0000000};
byte two[] = {B0111010, B0101010, B0101010, B0101110};
byte three[] = {B0111110, B0101010, B0101010, B0100010};
byte four[] = {B0000100, B0111110, B0000100, B0111100};
byte five[] = {B0101110, B0101010, B0101010, B0111010};
byte six[] = {B0001110, B0001010, B0001010, B0111110};
byte seven[] = {B0111110, B0100000, B0100000, B0110000};
byte eight[] = {B0111110, B0101010, B0101010, B0111110};
byte nine[] = {B0111110, B0101000, B0101000, B0111000};
// OLD FONT
// byte zero[] = {B0011100, B0100010, B0100010, B0011100};
// byte two[] = {B0010010, B0101010, B0100110, B0010010};
// byte three[] = {B0010100, B0101010, B0101010, B0100010};
// byte four[] = {B0000100, B0111110, B0010100, B0001100};
// byte five[] = {B0000100, B0101010, B0101010, B0111010};
// byte six[] = {B0000100, B0101010, B0101010, B0011100};
// byte seven[] = {B0110000, B0101000, B0100110, B0100000};
// byte eight[] = {B0010100, B0101010, B0101010, B0010100};
// byte nine[] = {B0011100, B0101010, B0101010, B0010000};
// first digit
byte side_one[] = {B0000000, B0111110, B0000000};
byte side_zero[] = {B0000000, B0000000, B0000000};
// brank space
byte space[] = {B0000000};
byte black[] = {B1111111};
// AM, PM
byte pm[] = {B0011110, B0001000, B0011110, B0000000, B0001000, B0010100, B0011110};
byte am[] = {B0011110, B0001000, B0011110, B0000000, B0001110, B0010100, B0001110};
// 28 byte data
byte iizukak[] = {B0000000, B0000000,
B0001010, B0000100, B0111110, // k
B0000000,
B0000010, B0001110, B0001010, B0001110, // a
B0000000,
B0001010, B0000100, B0111110, // k
B0000000,
B0001110, B0000010, B0001110, // u
B0000000,
B0011010, B0010110, B0010010, // z
B0000000,
B0101110, // i
B0000000,
B0101110, // i
B0000000, B0000000};
// data prefix
byte data_prefix[] = {0x80, 0x83, 0xFF};
// data prefix
byte data_suffix[] = {0x8F};
byte dot_on[] = {B0000000, B0010100, B0000000};
byte dot_off[] = {B0000000, B0000000, B0000000};
bool dot = true;
// Display one number to Flip Dot Display
void displayNumber(int n) {
switch(n){
case 0:
Serial.write(zero, 4);
break;
case 1:
Serial.write(one, 4);
break;
case 2:
Serial.write(two, 4);
break;
case 3:
Serial.write(three, 4);
break;
case 4:
Serial.write(four, 4);
break;
case 5:
Serial.write(five, 4);
break;
case 6:
Serial.write(six, 4);
break;
case 7:
Serial.write(seven, 4);
break;
case 8:
Serial.write(eight, 4);
break;
case 9:
Serial.write(nine, 4);
break;
default:
Serial.write(zero, 4);
}
return;
}
void setup() {
Serial.begin(57600);
pinMode(txden, OUTPUT);
digitalWrite(txden, HIGH); // master
/// Display auther name
Serial.write(data_prefix, 3);
Serial.write(iizukak, 28);
Serial.write(data_suffix, 1);
delay(5000);
// Display random number
/*
int i, j;
byte r[] = {0};
for (j = 0; j <= 100; j++){
Serial.write(data_prefix, 3);
for (i = 0; i < 28; i++){
r[0] = random(256);
Serial.write(r, 1);
}
Serial.write(data_suffix, 1);
delay(50);
}
*/
}
void loop() {
// delay between transmissions: 200 ms is a safe value for CE configuration, you can play with this. For 2C you should be able to ge down to 100 ms
int delay_tr = 1000;
tmElements_t tm;
if (RTC.read(tm)) {
// Serial.write(all_dark_2C, 32);
// Write protocol prefix
Serial.write(data_prefix, 3);
Serial.write(space, 1);
// AM, PM
if(tm.Hour < 12){
Serial.write(am, 7);
}else{
Serial.write(pm, 7);
}
Serial.write(space, 1);
// Display Munute
displayNumber(tm.Minute % 10);
Serial.write(space, 1);
displayNumber(tm.Minute / 10);
// Display Dot
/* Delte comment out if flip dot ON
if(dot == true){
Serial.write(dot_on, 3);
dot = false;
}else{
Serial.write(dot_off, 3);
dot = true;
}
*/
Serial.write(dot_on, 3);
// WriteHour
if(tm.Hour < 13){
if(tm.Hour < 10){
displayNumber(tm.Hour);
Serial.write(side_zero, 3);
}else{
displayNumber(tm.Hour % 10);
Serial.write(side_one, 3);
}
}else{
if(tm.Hour < 22){
displayNumber(tm.Hour - 12);
Serial.write(side_zero, 3);
}else{
displayNumber((tm.Hour - 12) % 10);
Serial.write(side_one, 3);
}
}
// Write Data
// Write protocol suffix
Serial.write(data_suffix, 1);
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(delay_tr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment