Skip to content

Commit a660f46

Browse files
Add files via upload
1 parent 61cd28d commit a660f46

File tree

3 files changed

+1303
-0
lines changed

3 files changed

+1303
-0
lines changed

EnigmaQRClock.ino

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// A QR Clock for the Arduino UNO + Seeed Touchscreen LCD platform
2+
// by @arduinoenigma
3+
// uses a modified @chooftech QR library and a modified Xark display driver
4+
// update times of a second are possible
5+
// http://ch00ftech.com/2013/04/23/optimizing-the-qr-clock/
6+
// http://ch00ftech.com/wp-content/uploads/2012/10/main1.c
7+
//
8+
// to set the time, open a serial monitor and type the following command
9+
// r1;h15;m22;s25;u10;d;x;
10+
// r1 sets rotation so plug is to the right. Any rotation is fine, setting is for purists
11+
// h15 sets hours to 15
12+
// m22 sets minutes to 22
13+
// s10 sets seconds to 25
14+
// u10 sets update rate to 10 seconds, 1,5,10,15,20,30,60 are valid
15+
// d shows the time
16+
// x starts the clock now
17+
// if a command with a two digit parameter is sent with two digits, the semicolon can be omitted
18+
// the following are valid strings
19+
// r1h15m22s25u10dx
20+
// r1h9;m5;s25u1;dx
21+
//
22+
23+
#define TFTSeed
24+
//#define TFTAdafruit
25+
26+
#include <SPI.h>
27+
#include <FastTftILI9341.h> //https://github.com/arduinoenigma/FastSeedTFTv2
28+
29+
PDQ_ILI9341 Tft;
30+
31+
//raw input string from user GLOBAL VAR to generate();
32+
char input[17];
33+
34+
//GLOBAL VAR to generate() and printcode();
35+
unsigned char outputmatrix[56] = {128, 63, 192, 247, 247, 137, 254, 34, 209, 95, 36, 250, 139, 124, 127, 31, 160, 10, 248, 255, 255, 191, 255, 255, 255, 255, 255, 254, 255, 255, 255, 255, 251, 255, 255, 253, 63, 224, 255, 247, 253, 255, 162, 255, 95, 244, 255, 139, 254, 127, 223, 255, 15, 248, 255, 255};
36+
37+
unsigned long ul_LastGenerated = 0UL;
38+
39+
byte hours = 0;
40+
byte mins = 0;
41+
byte secs = 0;
42+
byte ampm = 0;
43+
byte update = 10;
44+
byte rotation = 0;
45+
46+
byte xo = 15;
47+
byte yo = 55;
48+
49+
void advancetime()
50+
{
51+
input[0] = (hours / 10) + '0';
52+
input[1] = (hours - (hours / 10) * 10) + '0';
53+
input[2] = ':';
54+
input[3] = (mins / 10) + '0';
55+
input[4] = (mins - (mins / 10) * 10) + '0';
56+
57+
//input[5] = ';';
58+
//input[6] = 0;
59+
60+
input[5] = ':';
61+
input[6] = (secs / 10) + '0';
62+
input[7] = (secs - (secs / 10) * 10) + '0';
63+
input[8] = ';';
64+
input[9] = 0;
65+
66+
67+
secs += update;
68+
if (secs >= 60)
69+
{
70+
secs = secs - 60;
71+
mins++;
72+
if (mins == 60)
73+
{
74+
mins = 0;
75+
hours++;
76+
if (hours == 24)
77+
{
78+
mins = 0;
79+
hours = 0;
80+
}
81+
}
82+
}
83+
}
84+
85+
void setup() {
86+
Serial.begin(9600);
87+
Tft.TFTinit();
88+
89+
Serial.println("valid init string is: r1;h15;m22;s25;u10;d;x;");
90+
91+
advancetime();
92+
generate();
93+
ul_LastGenerated = millis();
94+
printcode(&outputmatrix[0]);
95+
96+
advancetime();
97+
generate();
98+
}
99+
100+
void loop() {
101+
102+
unsigned long ul_CurrentMillis;
103+
ul_CurrentMillis = millis();
104+
105+
SerialFSM();
106+
107+
if ((ul_CurrentMillis - ul_LastGenerated) >= (update * 1000))
108+
{
109+
ul_LastGenerated += update * 1000;
110+
printcode(&outputmatrix[0]);
111+
advancetime();
112+
generate();
113+
}
114+
115+
116+
117+
}

SerialMenu.ino

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
byte numberstocollect = 0;
2+
byte storenumbersin = 0;
3+
byte collectednumber = 0;
4+
byte finishedcollection = 1;
5+
6+
7+
//to setup r1h15m22s10u10dx
8+
//bug: h1m1s1 does not work
9+
10+
void SerialFSM()
11+
{
12+
13+
char KeyPressed = 0;
14+
15+
if (Serial.available())
16+
{
17+
KeyPressed = Serial.read();
18+
19+
switch (KeyPressed)
20+
{
21+
//set hours
22+
case 'H':
23+
case 'h':
24+
{
25+
collectednumber = 0;
26+
numberstocollect = 2;
27+
storenumbersin = 1;
28+
break;
29+
}
30+
31+
//set minutes
32+
case 'M':
33+
case 'm':
34+
{
35+
collectednumber = 0;
36+
numberstocollect = 2;
37+
storenumbersin = 2;
38+
break;
39+
}
40+
41+
//set seconds
42+
case 'S':
43+
case 's':
44+
{
45+
collectednumber = 0;
46+
numberstocollect = 2;
47+
storenumbersin = 3;
48+
break;
49+
}
50+
51+
//display AM/PM or 24hr
52+
case 'P':
53+
case 'p':
54+
{
55+
collectednumber = 0;
56+
numberstocollect = 1;
57+
storenumbersin = 4;
58+
break;
59+
}
60+
61+
//update every x seconds
62+
case 'U':
63+
case 'u':
64+
{
65+
collectednumber = 0;
66+
numberstocollect = 2;
67+
storenumbersin = 5;
68+
break;
69+
}
70+
71+
// set rotation
72+
case 'R':
73+
case 'r':
74+
{
75+
collectednumber = 0;
76+
numberstocollect = 1;
77+
storenumbersin = 6;
78+
break;
79+
}
80+
81+
// draw the time
82+
case 'D':
83+
case 'd':
84+
{
85+
Serial.print(hours);
86+
Serial.print(":");
87+
Serial.print(mins);
88+
Serial.print(":");
89+
Serial.println(secs);
90+
break;
91+
}
92+
93+
// start clock
94+
case 'X':
95+
case 'x':
96+
{
97+
ul_LastGenerated = millis();
98+
advancetime();
99+
advancetime();
100+
generate();
101+
break;
102+
}
103+
104+
// collect numeric parameter or ; as separator
105+
default:
106+
{
107+
if (numberstocollect)
108+
{
109+
finishedcollection = 0;
110+
if ((KeyPressed >= '0') && (KeyPressed <= '9'))
111+
{
112+
collectednumber = collectednumber * 10 + (KeyPressed - '0');
113+
numberstocollect--;
114+
if (numberstocollect == 0)
115+
{
116+
finishedcollection = 1;
117+
}
118+
}
119+
if (KeyPressed == ';')
120+
{
121+
finishedcollection = 1;
122+
}
123+
}
124+
125+
if (finishedcollection)
126+
{
127+
finishedcollection = 0;
128+
129+
switch (storenumbersin)
130+
{
131+
case 1:
132+
{
133+
hours = collectednumber;
134+
break;
135+
}
136+
case 2:
137+
{
138+
mins = collectednumber;
139+
break;
140+
}
141+
case 3:
142+
{
143+
secs = collectednumber;
144+
break;
145+
}
146+
case 4:
147+
{
148+
ampm = collectednumber;
149+
break;
150+
}
151+
case 5:
152+
{
153+
if ((collectednumber == 1) || (collectednumber == 5) || (collectednumber == 10) || (collectednumber == 15) || (collectednumber == 20) || (collectednumber == 30) || (collectednumber == 60))
154+
{
155+
update = collectednumber;
156+
}
157+
break;
158+
}
159+
case 6:
160+
{
161+
if (collectednumber < 4)
162+
{
163+
rotation = collectednumber;
164+
165+
if ((rotation==0) || (rotation==2))
166+
{
167+
xo = 15;
168+
yo = 55;
169+
}
170+
else
171+
{
172+
yo = 15;
173+
xo = 55;
174+
}
175+
176+
Tft.setRotation(rotation);
177+
Tft.fillScreen(BLACK);
178+
printcode(&outputmatrix[0]);
179+
}
180+
break;
181+
}
182+
}
183+
184+
}
185+
186+
break;
187+
}
188+
}
189+
190+
191+
}
192+
}

0 commit comments

Comments
 (0)