forked from wouterdevinck/nixie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nixie.ino
127 lines (103 loc) · 3.31 KB
/
nixie.ino
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Nixie clock firmware
// ====================
// December 2016 - April 2017
// by Wouter Devinck
// Dependencies
// ------------
// * Arduino core
// * Chronodot library (for DS3231) - https://github.com/Stephanie-Maks/Arduino-Chronodot
// Block diagram
// -------------
// +----------+
// | | +----------+
// | DS3231 +---+3V battery|
// | | +----------+
// +----------+
// |
// | I2C
// +---+ |
// |SW1| +--------------+ +----------+ +----------+
// +---+---+ | | | | |
// | ATmega328p +-----+ HV5622 +-----+ HV5622 |
// +---+---+ | | | | |
// |SW2| +--------------+ +----------+ +----------+
// +---+ | | | | | | | | |
// +------------+ +----+ | +---+ | +----+ | +---+ |
// | | |IN14| | |IN3| | |IN14| | |IN3| |
// | DC/DC 170V | +----+ | +---+ | +----+ | +---+ |
// | | +----+ +----+ +----+ +----+
// +------------+ |IN14| |IN14| |IN14| |IN14|
// +----+ +----+ +----+ +----+
#include "TaskScheduler.h"
#include "NixieDisplay.h"
#include "HvSupply.h"
#include "Settings.h"
#include "Chronodot.h"
#include "TimeTask.h"
#include "MenuTask.h"
#include "ButtonsTask.h"
#include <Wire.h>
// Real time clock
Chronodot rtc;
// "Real Time OS" - simple task scheduler
TaskScheduler sched;
// HV shift registers
NixieDisplay nixie;
// DC/DC converter (enable pin is connected to a GPIO)
HvSupply hvsupply;
// DST settings in EEPROM
Settings settings;
// Tasks that run periodically
TimeTask timeTask(&nixie, &rtc, &settings); // Update displayed time
MenuTask menuTask(&nixie, &rtc, &hvsupply, &settings); // Read from the serial port
ButtonsTask buttonsTask(&rtc, &timeTask); // Read from the HW buttons
void setup() {
// Start serial
Serial.begin(9600);
Serial.println(F("[INFO] Nixie clock is booting..."));
// Debug: reset reason
switch (MCUSR) {
case 2:
Serial.println(F("[DEBUG] Reset caused by reset pin or software reset"));
break;
case 7:
Serial.println(F("[DEBUG] Reset caused by loss of power"));
break;
}
MCUSR = 0;
// Initiate the Real Time Clock
Serial.println(F("[INFO] 1. Init real time clock"));
timeTask.begin();
// Initiate the button inputs
Serial.println(F("[INFO] 2. Init buttons"));
buttonsTask.begin();
// Initiate the HV5622 outputs
Serial.println(F("[INFO] 3. Init HV shift registers"));
nixie.begin();
// Initiate the DC/DC enable pin
Serial.println(F("[INFO] 4. Init DC/DC"));
hvsupply.begin();
// Read settings from EEPROM
Serial.println(F("[INFO] 5. Read settings from EEPROM"));
settings.begin();
// Initiate the OS tasks
Serial.println(F("[INFO] 6. Init RTOS tasks"));
sched.addTask(execMenuTask, 100);
sched.addTask(execButtonsTask, 100);
sched.addTask(execTimeTask, 500);
// Debug info
Serial.println(F("[INFO] Clock done booting."));
menuTask.printMenu();
}
void loop() {
sched.loop();
}
void execTimeTask() {
timeTask.task();
}
void execButtonsTask() {
buttonsTask.task();
}
void execMenuTask() {
menuTask.task();
}