23
23
#include < SPI.h>
24
24
#include < Adafruit_LIS3DH.h>
25
25
#include < Adafruit_Sensor.h>
26
+ #include < Adafruit_NeoPixel.h>
26
27
27
- // set DEBUG to True to view accel outputs
28
- #define DEBUG false
29
28
// Used for Pizeo
30
29
#define PIEZO_PIN 0
30
+
31
+ // Pin connected to NeoPixels
32
+ #define PIXELPIN 6
33
+
34
+ // Number of NeoPixels
35
+ #define NUMPIXELS 16
36
+
31
37
// Used for software SPI
32
38
#define LIS3DH_CLK 13
33
39
#define LIS3DH_MISO 12
38
44
// I2C
39
45
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
40
46
47
+ // set up neopixel strip
48
+ Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIXELPIN, NEO_GRB + NEO_KHZ800);
49
+
41
50
// Set up the 'cubeTask' feed
42
51
AdafruitIO_Feed *cubetask = io.feed(" cubetask" );
43
52
@@ -65,7 +74,7 @@ int sendDelay = 0.5;
65
74
unsigned long currentTime;
66
75
unsigned long prevTime;
67
76
int seconds = 0 ;
68
- int minutes = 0 ;
77
+ double minutes = 0 ;
69
78
70
79
void setup ()
71
80
{
@@ -74,18 +83,22 @@ void setup()
74
83
// wait for serial monitor to open
75
84
while (!Serial)
76
85
;
86
+
77
87
Serial.println (" Adafruit IO Time Tracking Cube" );
78
88
79
89
// Initialize LIS3DH
80
90
if (!lis.begin (0x18 ))
81
91
{
82
- Serial.println (" Couldnt start" );
92
+ Serial.println (" Couldnt start LIS3DH " );
83
93
while (1 )
84
94
;
85
95
}
86
96
Serial.println (" LIS3DH found!" );
87
97
lis.setRange (LIS3DH_RANGE_4_G);
88
98
99
+ // Initialize NeoPixel library
100
+ pixels.begin ();
101
+
89
102
// connect to io.adafruit.com
90
103
Serial.print (" Connecting to Adafruit IO" );
91
104
io.connect ();
@@ -114,6 +127,16 @@ void updateTime()
114
127
}
115
128
}
116
129
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
+
117
140
void loop ()
118
141
{
119
142
// io.run(); is required for all sketches.
@@ -152,24 +175,28 @@ void loop()
152
175
switch (cubeState)
153
176
{
154
177
case 1 :
178
+ // Set pixels to green color
179
+ setPixels (0 , 150 , 0 );
155
180
Serial.println (" Playing Task 1 Sound..." );
156
181
tone (PIEZO_PIN, 650 , 300 );
157
182
Serial.print (" Sending to Adafruit IO -> " );
158
183
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);
162
187
// reset the timer
163
188
minutes = 0 ;
164
189
break ;
165
190
case 2 :
191
+ // Set pixels to red color
192
+ setPixels (150 , 0 , 0 );
166
193
Serial.println (" Playing Sound 2 Sound..." );
167
194
tone (PIEZO_PIN, 850 , 300 );
168
195
Serial.print (" Sending to Adafruit IO -> " );
169
196
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);
173
200
// reset the timer
174
201
minutes = 0 ;
175
202
break ;
@@ -180,4 +207,4 @@ void loop()
180
207
181
208
// Delay the send to Adafruit IO
182
209
delay (sendDelay * 1000 );
183
- }
210
+ }
0 commit comments