2525#include < Adafruit_Sensor.h>
2626#include < Adafruit_NeoPixel.h>
2727
28- // Used for Pizeo
29- #define PIEZO_PIN 0
30-
31- // NeoPixel Pin on Prop-Maker FeatherWing
32- #define NEOPIXEL_PIN 5
33-
34- // # of Pixels Attached
35- #define NUM_PIXELS 8
36-
3728// Prop-Maker Wing
3829#define NEOPIXEL_PIN 2
3930#define POWER_PIN 15
4031#define RED_LED 13
4132#define GREEN_LED 12
4233#define BLUE_LED 14
4334
44- // Library Setup
45- Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
35+ // Used for Pizeo
36+ #define PIEZO_PIN 0
37+
38+ // NeoPixel Pin
39+ #define NEOPIXEL_PIN 5
40+
41+ // # of Pixels Attached
42+ #define NUM_PIXELS 8
4643
4744// Used for software SPI
4845#define LIS3DH_CLK 13
@@ -51,15 +48,15 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB +
5148// Used for hardware & software SPI
5249#define LIS3DH_CS 10
5350
54- // I2C
51+ // Adafruit_LIS3DH Setup
5552Adafruit_LIS3DH lis = Adafruit_LIS3DH();
5653
54+ // NeoPixel Setup
55+ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
56+
5757// Set up the 'cubeTask' feed
5858AdafruitIO_Feed *cubetask = io.feed(" cubetask" );
5959
60- // Set up the 'minutes' feed
61- AdafruitIO_Feed *cubeminutes = io.feed(" cubeminutes" );
62-
6360/* Time Tracking Cube States
6461 * 0: Neutral, Cube on Base
6562 * 1: Cube Tilted, Left on X-Axis
@@ -68,14 +65,13 @@ AdafruitIO_Feed *cubeminutes = io.feed("cubeminutes");
6865int cubeState = 0 ;
6966
7067// Previous cube orientation state
71- int lastCubeState = 0 ;
68+ int prvCubeState = 0 ;
7269
7370// Tasks (change these to what you're currently working on)
7471String taskOne = " Write Learn Guide" ;
7572String taskTwo = " Write Code" ;
76- String taskThree = " Taking a Break!" ;
7773
78- // Adafruit IO Sending Delay , in seconds
74+ // Adafruit IO sending delay , in seconds
7975int sendDelay = 0.5 ;
8076
8177// Time-Keeping
@@ -93,7 +89,7 @@ void setup()
9389 ;
9490 Serial.println (" Adafruit IO Time Tracking Cube" );
9591
96- // Enabling NeoPixel and PWR mode
92+ // enabling RGB and NeoPixels on Prop-Maker Featherwing
9793 pinMode (POWER_PIN, OUTPUT);
9894 digitalWrite (POWER_PIN, LOW);
9995 pinMode (RED_LED, OUTPUT);
@@ -115,7 +111,7 @@ void setup()
115111 Serial.println (" LIS3DH found!" );
116112 lis.setRange (LIS3DH_RANGE_4_G);
117113
118- // This initializes the NeoPixel library.
114+ // Initialize NeoPixel Strip
119115 strip.begin ();
120116 Serial.println (" Pixels init'd" );
121117
@@ -141,7 +137,7 @@ void updateTime()
141137 // grab the current time from millis()
142138 currentTime = millis () / 1000 ;
143139 seconds = currentTime - prevTime;
144- // increase min. timer
140+ // increase mins.
145141 if (seconds == 60 )
146142 {
147143 prevTime = currentTime;
@@ -177,8 +173,7 @@ void loop()
177173 sensors_event_t event;
178174 lis.getEvent (&event);
179175
180-
181- // Detect Cube Face Orientation
176+ // Detect cube face orientation
182177 if (event.acceleration .x > 9 && event.acceleration .x < 10 ) // left-side up
183178 {
184179 // Serial.println("Cube TILTED: Left");
@@ -194,38 +189,37 @@ void loop()
194189 cubeState = 3 ;
195190 }
196191 else
197- { // orientation not found
192+ { // orientation not specified
198193 }
199194
200195 // return if the orientation hasn't changed
201- if (cubeState == lastCubeState )
196+ if (cubeState == prvCubeState )
202197 return ;
203198
204-
205- // Send to Adafruit IO based off of the orientation of the Cube
199+ // Send to Adafruit IO based off of the orientation of the cube
206200 switch (cubeState)
207201 {
208202 case 1 :
209203 Serial.println (" Switching to Task 1" );
204+ // update the neopixel strip
210205 updatePixels (50 , 0 , 0 );
206+ // play a sound
211207 tone (PIEZO_PIN, 650 , 300 );
212208 Serial.print (" Sending to Adafruit IO -> " );
213209 Serial.println (taskTwo);
214- cubetask->save (taskTwo);
215- // save previous task's minutes to a feed
216- cubeminutes->save (minutes);
210+ cubetask->save (taskTwo, minutes);
217211 // reset the timer
218212 minutes = 0 ;
219213 break ;
220214 case 2 :
221215 Serial.println (" Switching to Task 2" );
216+ // update the neopixel strip
222217 updatePixels (0 , 50 , 0 );
218+ // play a sound
223219 tone (PIEZO_PIN, 850 , 300 );
224220 Serial.print (" Sending to Adafruit IO -> " );
225221 Serial.println (taskOne);
226- cubetask->save (taskOne);
227- // save previous task's minutes to a feed
228- cubeminutes->save (minutes);
222+ cubetask->save (taskOne, minutes);
229223 // reset the timer
230224 minutes = 0 ;
231225 break ;
@@ -235,8 +229,8 @@ void loop()
235229 break ;
236230 }
237231
238- // store last cube orientation state
239- lastCubeState = cubeState;
232+ // save cube state
233+ prvCubeState = cubeState;
240234
241235 // Delay the send to Adafruit IO
242236 delay (sendDelay * 1000 );
0 commit comments