@@ -41,6 +41,9 @@ Adafruit_LIS3DH lis = Adafruit_LIS3DH();
4141// Set up the 'orientation' feed
4242AdafruitIO_Feed *orientation = io.feed(" orientation" );
4343
44+ // Set up the 'minutes' feed
45+ AdafruitIO_Feed *cubeminutes = io.feed(" cubeminutes" );
46+
4447/* Time Tracking Cube States
4548 * 0: Neutral, Cube on Base
4649 * 1: Cube Tilted, Left on X-Axis
@@ -51,13 +54,20 @@ int cubeState = 0;
5154// Previous cube orientation state
5255int lastCubeState = 0 ;
5356
54- // Tasks
57+ // Tasks (change these to what you're currently working on)
5558String taskOne = " Write Learn Guide" ;
5659String taskTwo = " Write Code" ;
5760
5861// Adafruit IO Sending Delay, in seconds
5962int sendDelay = 0.5 ;
6063
64+ // Time-Keeping
65+ unsigned long currentTime;
66+ unsigned long prevTime;
67+ int seconds = 0 ;
68+ int minutes = 0 ;
69+ int prevMinutes = 0 ;
70+
6171void setup ()
6272{
6373 // start the serial connection
@@ -93,31 +103,33 @@ void setup()
93103 Serial.println (io.statusText ());
94104}
95105
96- void loop ()
106+ void updateTime ()
97107{
108+ currentTime = millis () / 1000 ;
109+ seconds = currentTime - prevTime;
110+ // increase min. timer
111+ if (seconds == 60 )
112+ {
113+ prevTime = currentTime;
114+ minutes++;
115+ }
116+ }
98117
118+ void loop ()
119+ {
99120 // io.run(); is required for all sketches.
100121 // it should always be present at the top of your loop
101122 // function. it keeps the client connected to
102123 // io.adafruit.com, and processes any incoming data.
103124 io.run ();
104125
126+ // Update the timer
127+ updateTime ();
128+
105129 // Get a normalized sensor reading
106130 sensors_event_t event;
107131 lis.getEvent (&event);
108132
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-
121133 // Detect Cube Face Orientation
122134 if (event.acceleration .x > 9 && event.acceleration .x < 10 )
123135 {
@@ -131,7 +143,6 @@ void loop()
131143 }
132144 else
133145 { // orientation not found
134- Serial.println (" Undefined Orientation" );
135146 }
136147
137148 // return if the value hasn't changed
@@ -147,13 +158,21 @@ void loop()
147158 Serial.print (" Sending to Adafruit IO -> " );
148159 Serial.println (taskOne);
149160 orientation->save (taskOne);
161+ // save minutes to a feed
162+ cubeminutes->save (minutes);
163+ // reset the timer
164+ minutes = 0 ;
150165 break ;
151166 case 2 :
152167 Serial.println (" Playing Sound 2 Sound..." );
153168 tone (PIEZO_PIN, 850 , 300 );
154169 Serial.print (" Sending to Adafruit IO -> " );
155170 Serial.println (taskTwo);
156171 orientation->save (taskTwo);
172+ // save minutes to a feed
173+ cubeminutes->save (minutes);
174+ // reset the timer
175+ minutes = 0 ;
157176 break ;
158177 }
159178
@@ -162,4 +181,4 @@ void loop()
162181
163182 // Delay the send to Adafruit IO
164183 delay (sendDelay * 1000 );
165- }
184+ }
0 commit comments