2323#include < SPI.h>
2424#include < Adafruit_LIS3DH.h>
2525#include < Adafruit_Sensor.h>
26+ #include < Adafruit_NeoPixel.h>
2627
27- // set DEBUG to True to view accel outputs
28- #define DEBUG false
2928// Used for Pizeo
3029#define PIEZO_PIN 0
30+
31+ // Pin connected to NeoPixels
32+ #define PIXELPIN 6
33+
34+ // Number of NeoPixels
35+ #define NUMPIXELS 16
36+
3137// Used for software SPI
3238#define LIS3DH_CLK 13
3339#define LIS3DH_MISO 12
3844// I2C
3945Adafruit_LIS3DH lis = Adafruit_LIS3DH();
4046
47+ // set up neopixel strip
48+ Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIXELPIN, NEO_GRB + NEO_KHZ800);
49+
4150// Set up the 'cubeTask' feed
4251AdafruitIO_Feed *cubetask = io.feed(" cubetask" );
4352
@@ -65,7 +74,7 @@ int sendDelay = 0.5;
6574unsigned long currentTime;
6675unsigned long prevTime;
6776int seconds = 0 ;
68- int minutes = 0 ;
77+ double minutes = 0 ;
6978
7079void setup ()
7180{
@@ -74,18 +83,22 @@ void setup()
7483 // wait for serial monitor to open
7584 while (!Serial)
7685 ;
86+
7787 Serial.println (" Adafruit IO Time Tracking Cube" );
7888
7989 // Initialize LIS3DH
8090 if (!lis.begin (0x18 ))
8191 {
82- Serial.println (" Couldnt start" );
92+ Serial.println (" Couldnt start LIS3DH " );
8393 while (1 )
8494 ;
8595 }
8696 Serial.println (" LIS3DH found!" );
8797 lis.setRange (LIS3DH_RANGE_4_G);
8898
99+ // Initialize NeoPixel library
100+ pixels.begin ();
101+
89102 // connect to io.adafruit.com
90103 Serial.print (" Connecting to Adafruit IO" );
91104 io.connect ();
@@ -114,6 +127,16 @@ void updateTime()
114127 }
115128}
116129
130+
131+ void setPixels (int red, int green, int blue) {
132+ for (int i=0 ;i<NUMPIXELS;i++){
133+ // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
134+ pixels.setPixelColor (i, pixels.Color (red,green,blue)); // Moderately bright green color.
135+ pixels.show (); // This sends the updated pixel color to the hardware.
136+ delay (500 ); // Delay for a period of time (in milliseconds).
137+ }
138+ }
139+
117140void loop ()
118141{
119142 // io.run(); is required for all sketches.
@@ -152,24 +175,28 @@ void loop()
152175 switch (cubeState)
153176 {
154177 case 1 :
178+ // Set pixels to green color
179+ setPixels (0 , 150 , 0 );
155180 Serial.println (" Playing Task 1 Sound..." );
156181 tone (PIEZO_PIN, 650 , 300 );
157182 Serial.print (" Sending to Adafruit IO -> " );
158183 Serial.println (taskOne);
159- cubetask->save (taskOne);
160- // save minutes to a feed
161- cubeminutes-> save (minutes);
184+ cubetask->save (taskOne, minutes );
185+ Serial. println ( " Task Mins: " );
186+ Serial. println (minutes);
162187 // reset the timer
163188 minutes = 0 ;
164189 break ;
165190 case 2 :
191+ // Set pixels to red color
192+ setPixels (150 , 0 , 0 );
166193 Serial.println (" Playing Sound 2 Sound..." );
167194 tone (PIEZO_PIN, 850 , 300 );
168195 Serial.print (" Sending to Adafruit IO -> " );
169196 Serial.println (taskTwo);
170- cubetask->save (taskTwo);
171- // save minutes to a feed
172- cubeminutes-> save (minutes);
197+ cubetask->save (taskTwo, minutes );
198+ Serial. println ( " Task Mins: " );
199+ Serial. println (minutes);
173200 // reset the timer
174201 minutes = 0 ;
175202 break ;
@@ -180,4 +207,4 @@ void loop()
180207
181208 // Delay the send to Adafruit IO
182209 delay (sendDelay * 1000 );
183- }
210+ }
0 commit comments