@@ -41,6 +41,9 @@ Adafruit_LIS3DH lis = Adafruit_LIS3DH();
41
41
// Set up the 'orientation' feed
42
42
AdafruitIO_Feed *orientation = io.feed(" orientation" );
43
43
44
+ // Set up the 'minutes' feed
45
+ AdafruitIO_Feed *cubeminutes = io.feed(" cubeminutes" );
46
+
44
47
/* Time Tracking Cube States
45
48
* 0: Neutral, Cube on Base
46
49
* 1: Cube Tilted, Left on X-Axis
@@ -51,13 +54,20 @@ int cubeState = 0;
51
54
// Previous cube orientation state
52
55
int lastCubeState = 0 ;
53
56
54
- // Tasks
57
+ // Tasks (change these to what you're currently working on)
55
58
String taskOne = " Write Learn Guide" ;
56
59
String taskTwo = " Write Code" ;
57
60
58
61
// Adafruit IO Sending Delay, in seconds
59
62
int sendDelay = 0.5 ;
60
63
64
+ // Time-Keeping
65
+ unsigned long currentTime;
66
+ unsigned long prevTime;
67
+ int seconds = 0 ;
68
+ int minutes = 0 ;
69
+ int prevMinutes = 0 ;
70
+
61
71
void setup ()
62
72
{
63
73
// start the serial connection
@@ -93,31 +103,33 @@ void setup()
93
103
Serial.println (io.statusText ());
94
104
}
95
105
96
- void loop ()
106
+ void updateTime ()
97
107
{
108
+ currentTime = millis () / 1000 ;
109
+ seconds = currentTime - prevTime;
110
+ // increase min. timer
111
+ if (seconds == 60 )
112
+ {
113
+ prevTime = currentTime;
114
+ minutes++;
115
+ }
116
+ }
98
117
118
+ void loop ()
119
+ {
99
120
// io.run(); is required for all sketches.
100
121
// it should always be present at the top of your loop
101
122
// function. it keeps the client connected to
102
123
// io.adafruit.com, and processes any incoming data.
103
124
io.run ();
104
125
126
+ // Update the timer
127
+ updateTime ();
128
+
105
129
// Get a normalized sensor reading
106
130
sensors_event_t event;
107
131
lis.getEvent (&event);
108
132
109
- // Optionally display the accelerometer values
110
- #ifdef DEBUG
111
- Serial.print (" \t\t X: " );
112
- Serial.print (event.acceleration .x );
113
- Serial.print (" \t Y: " );
114
- Serial.print (event.acceleration .y );
115
- Serial.print (" \t Z: " );
116
- Serial.print (event.acceleration .z );
117
- Serial.println (" m/s^2 " );
118
- Serial.println ();
119
- #endif
120
-
121
133
// Detect Cube Face Orientation
122
134
if (event.acceleration .x > 9 && event.acceleration .x < 10 )
123
135
{
@@ -131,7 +143,6 @@ void loop()
131
143
}
132
144
else
133
145
{ // orientation not found
134
- Serial.println (" Undefined Orientation" );
135
146
}
136
147
137
148
// return if the value hasn't changed
@@ -147,13 +158,21 @@ void loop()
147
158
Serial.print (" Sending to Adafruit IO -> " );
148
159
Serial.println (taskOne);
149
160
orientation->save (taskOne);
161
+ // save minutes to a feed
162
+ cubeminutes->save (minutes);
163
+ // reset the timer
164
+ minutes = 0 ;
150
165
break ;
151
166
case 2 :
152
167
Serial.println (" Playing Sound 2 Sound..." );
153
168
tone (PIEZO_PIN, 850 , 300 );
154
169
Serial.print (" Sending to Adafruit IO -> " );
155
170
Serial.println (taskTwo);
156
171
orientation->save (taskTwo);
172
+ // save minutes to a feed
173
+ cubeminutes->save (minutes);
174
+ // reset the timer
175
+ minutes = 0 ;
157
176
break ;
158
177
}
159
178
@@ -162,4 +181,4 @@ void loop()
162
181
163
182
// Delay the send to Adafruit IO
164
183
delay (sendDelay * 1000 );
165
- }
184
+ }
0 commit comments