-
Notifications
You must be signed in to change notification settings - Fork 0
/
SevSegTimer.ino
81 lines (72 loc) · 1.55 KB
/
SevSegTimer.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
#include <LedControl.h>
#include "LedControl.h"
/* data,clock,load,numDevices */
LedControl lc=LedControl(5,3,4,1);
String state;
unsigned long runTime;
unsigned long counter;
unsigned long lastCheck;
void setup()
{
Serial.begin(9600);
pinMode(8, INPUT_PULLUP);
runTime = 0;
lc.shutdown(0, false);
lc.setIntensity(0,15);
lc.clearDisplay(0);
state = "running";
}
void display(unsigned long count)
{
unsigned long temp = count;
int digitValue;
int cursor = 0;
digitValue = temp%10;
temp = temp/10;
lc.setDigit(0, cursor, digitValue, false);
while( temp != 0 ) {
cursor++;
digitValue = temp%10;
temp = temp/10;
lc.setDigit(0, cursor, digitValue, false);
}
}
void loop()
{
unsigned long newCheck = millis();
int latchState;
if( newCheck - lastCheck > 999 ) {
latchState = digitalRead(8);
if( latchState == HIGH ) { //door is open
state = "stopped";
}
else { //door is closed
state = "running";
}
if( Serial.available() > 0 ) {
String command = Serial.readString();
if( command == "hide" ) {
lc.shutdown(0, true);
}
else if( command == "show" ) {
lc.shutdown(0, false);
}
else if( command == "reset" ) {
counter = 0;
}
else if( command == "stop" ) {
state = "stopped";
}
else if( command == "start" ) {
state = "running";
}
}
}
if( state == "running" ) {
if( newCheck - lastCheck > 999 ) {
counter++;
lastCheck = newCheck;
display(counter);
}
}
}