Assuming the jumper wires from the clock are connected to pins D1 and D2 on the ESP-12, the following Arduino sketch will make it function as a normal clock that ticks every second:
To be continued...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | tickPin = D1; os_timer_t secTimer; // Triggered by system timer every second void timerCallback(void *pArg) { tickOccured = true; } void setup() { // Setup GPIO outputs pinMode(D1, OUTPUT); pinMode(D2, OUTPUT); digitalWrite(D1, LOW); digitalWrite(D2, LOW); // Start system timer which triggers every second os_timer_setfn(&secTimer, timerCallback, NULL); os_timer_arm(&secTimer, 1000, true); } void loop() { if (tickOccured) { tickOccurred - false; tickPin = (tickPin == D1 ? D2: D1); digitalWrite(tickPin, HIGH); delay(100); digitalWrite(tickPin, LOW); delay(100); } delay(250); } |
To be continued...
You refer to D1 & D2 on your board, however I'm having trouble translating that to a normal ESP-12. Could you tell me which pins you have defaulted to using this diagram?
ReplyDeletehttp://simba-os.readthedocs.io/en/latest/_images/esp12e-pinout.png
From this link:
Deletehttp://www.esp8266.com/viewtopic.php?f=21&t=1388
I believe D1 = IO14, D2 = IO12
Thanks for sharing! I'm using this for an art project at the FB HQ.
ReplyDeleteA few comments:
Line 23 should be: tickOccurred = false;
And in some places of the code there's a typo — you use "tickOccured" instead of "tickOccurred".
Thanks for pointing out the spelling error. I have corrected it in the Github repo.
Delete