-
Notifications
You must be signed in to change notification settings - Fork 0
/
AntiRSI-ATTiny.ino
160 lines (151 loc) · 4.38 KB
/
AntiRSI-ATTiny.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
WorkRave-uino
Date: 11/2/15 20:21 EST
Coder: Flame Soulis (Daniel Pearce)
*/
//LED Handlers
#define LED_HEARTBEAT 0
#define LED_MICROPAUSE 3
#define LED_RESTBREAK 4
//Buzzer
#define BUZZER_PORT 3
//Time Handlers
#define TIME_TICK 100
#define TIME_MICROWARN 150
#define TIME_MICROPAUSE 3000
#define TIME_MICROEVENT 200
#define TIME_RESTWARN 300
#define TIME_RESTBREAK 27000
#define TIME_RESTEVENT 3000
//Stages
#define STAGE_IDLE 1
#define STAGE_MICROWARN 2
#define STAGE_MICROEVENT 3
#define STAGE_RESTWARN 4
#define STAGE_RESTEVENT 5
//Global
int iStageTimer;
int iRestBreakTimer;
unsigned long lOperationTime;
byte bStageMode;
void setup() {
//Setup global variables
iStageTimer = (TIME_MICROPAUSE - TIME_MICROWARN);
iRestBreakTimer = (TIME_RESTBREAK - TIME_RESTWARN);
bStageMode = STAGE_IDLE;
//Setup Pins
pinMode(LED_HEARTBEAT, OUTPUT);
pinMode(LED_MICROPAUSE, OUTPUT);
pinMode(LED_RESTBREAK, OUTPUT);
pinMode(BUZZER_PORT, OUTPUT);
//Test Flash
byte a; bool b=true;
for(a=0;a<20;++a) {
b=!b;
digitalWrite(LED_MICROPAUSE,(b) ? HIGH : LOW);
digitalWrite(LED_RESTBREAK,(!b) ? HIGH : LOW);
delay(250);
}
//Reset to low and begin!
digitalWrite(LED_RESTBREAK, LOW);
digitalWrite(LED_MICROPAUSE, LOW);
}
void loop() {
//Grab the current 'time'
lOperationTime = millis();
//Do actions based on the current stage
switch(bStageMode) {
//IDLE
case STAGE_IDLE:
//Handle Ticks
--iStageTimer;
--iRestBreakTimer;
//Check handles for events
if(!iRestBreakTimer) {
//Change stage to Rest Warning
bStageMode = STAGE_RESTWARN;
//Set timer to rest break's warning timer
iStageTimer = TIME_RESTWARN;
} else if(!iStageTimer) {
//Change stage to Micro Warning
bStageMode = STAGE_MICROWARN;
//Set timer to micro pause's warning timer
iStageTimer = TIME_MICROWARN;
}
break;
//MICRO PAUSE WARNING
case STAGE_MICROWARN:
//Handle only the stage's timer
--iStageTimer;
//Engage buzzer to grab user's attention
//(Every 10 ticks, toggle the buzzer on and off)
digitalWrite(BUZZER_PORT, (iStageTimer/10) % 2 != 0);
//Blink the Micro Pause LED
digitalWrite(LED_MICROPAUSE, (iStageTimer/5) % 3 != 0);
//Check if we need to enter Micro Pause Event
if(!iStageTimer) {
//Change stage to Micro Event
bStageMode = STAGE_MICROEVENT;
//Set timer to micro puase's event timer
iStageTimer = TIME_MICROEVENT;
//Disable the buzzer to be safe
digitalWrite(BUZZER_PORT, LOW);
//Enable the light for next stage
digitalWrite(LED_MICROPAUSE, HIGH);
}
break;
//MICRO PAUSE EVENT
case STAGE_MICROEVENT:
//Handle only the stage's timer
--iStageTimer;
//Check if we need to enter Micro Pause Event
if(!iStageTimer) {
//Change stage to Micro Event
bStageMode = STAGE_IDLE;
//Set timer to micro puase's event timer
iStageTimer = (TIME_MICROPAUSE - TIME_MICROWARN);
//Turn the LED off
digitalWrite(LED_MICROPAUSE, LOW);
}
break;
//REST BREAK WARNING
case STAGE_RESTWARN:
//Handle only the stage's timer
--iStageTimer;
//Engage buzzer to grab user's attention
//(Every 10 ticks, toggle the buzzer on and off)
digitalWrite(BUZZER_PORT, (iStageTimer/10) % 2 != 0);
//Blink the Micro Pause LED
digitalWrite(LED_RESTBREAK, (iStageTimer/5) % 3 != 0);
//Check if we need to enter Micro Pause Event
if(!iStageTimer) {
//Change stage to Micro Event
bStageMode = STAGE_RESTEVENT;
//Set timer to micro puase's event timer
iStageTimer = TIME_RESTEVENT;
//Disable the buzzer to be safe
digitalWrite(BUZZER_PORT, LOW);
//Enable the light for next stage
digitalWrite(LED_RESTBREAK, HIGH);
}
break;
//REST BREAK EVENT
case STAGE_RESTEVENT:
//Handle only the stage's timer
--iStageTimer;
//Check if we need to enter Micro Pause Event
if(!iStageTimer) {
//Change stage to Micro Event
bStageMode = STAGE_IDLE;
//Set timer to rest break's event timer and micro pause
iStageTimer = (TIME_MICROPAUSE - TIME_MICROWARN);
iRestBreakTimer = (TIME_RESTBREAK - TIME_RESTWARN);
//Turn the LED off
digitalWrite(LED_RESTBREAK, LOW);
}
break;
}
//Sleep for the tick
//(smartly by checking how long it took to do the loop)
delay(TIME_TICK - (millis()-lOperationTime));
}