25
25
#include < Adafruit_Sensor.h>
26
26
#include < Adafruit_NeoPixel.h>
27
27
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
-
37
28
// Prop-Maker Wing
38
29
#define NEOPIXEL_PIN 2
39
30
#define POWER_PIN 15
40
31
#define RED_LED 13
41
32
#define GREEN_LED 12
42
33
#define BLUE_LED 14
43
34
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
46
43
47
44
// Used for software SPI
48
45
#define LIS3DH_CLK 13
@@ -51,15 +48,15 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB +
51
48
// Used for hardware & software SPI
52
49
#define LIS3DH_CS 10
53
50
54
- // I2C
51
+ // Adafruit_LIS3DH Setup
55
52
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
56
53
54
+ // NeoPixel Setup
55
+ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
56
+
57
57
// Set up the 'cubeTask' feed
58
58
AdafruitIO_Feed *cubetask = io.feed(" cubetask" );
59
59
60
- // Set up the 'minutes' feed
61
- AdafruitIO_Feed *cubeminutes = io.feed(" cubeminutes" );
62
-
63
60
/* Time Tracking Cube States
64
61
* 0: Neutral, Cube on Base
65
62
* 1: Cube Tilted, Left on X-Axis
@@ -68,14 +65,13 @@ AdafruitIO_Feed *cubeminutes = io.feed("cubeminutes");
68
65
int cubeState = 0 ;
69
66
70
67
// Previous cube orientation state
71
- int lastCubeState = 0 ;
68
+ int prvCubeState = 0 ;
72
69
73
70
// Tasks (change these to what you're currently working on)
74
71
String taskOne = " Write Learn Guide" ;
75
72
String taskTwo = " Write Code" ;
76
- String taskThree = " Taking a Break!" ;
77
73
78
- // Adafruit IO Sending Delay , in seconds
74
+ // Adafruit IO sending delay , in seconds
79
75
int sendDelay = 0.5 ;
80
76
81
77
// Time-Keeping
@@ -93,7 +89,7 @@ void setup()
93
89
;
94
90
Serial.println (" Adafruit IO Time Tracking Cube" );
95
91
96
- // Enabling NeoPixel and PWR mode
92
+ // enabling RGB and NeoPixels on Prop-Maker Featherwing
97
93
pinMode (POWER_PIN, OUTPUT);
98
94
digitalWrite (POWER_PIN, LOW);
99
95
pinMode (RED_LED, OUTPUT);
@@ -115,7 +111,7 @@ void setup()
115
111
Serial.println (" LIS3DH found!" );
116
112
lis.setRange (LIS3DH_RANGE_4_G);
117
113
118
- // This initializes the NeoPixel library.
114
+ // Initialize NeoPixel Strip
119
115
strip.begin ();
120
116
Serial.println (" Pixels init'd" );
121
117
@@ -141,7 +137,7 @@ void updateTime()
141
137
// grab the current time from millis()
142
138
currentTime = millis () / 1000 ;
143
139
seconds = currentTime - prevTime;
144
- // increase min. timer
140
+ // increase mins.
145
141
if (seconds == 60 )
146
142
{
147
143
prevTime = currentTime;
@@ -177,8 +173,7 @@ void loop()
177
173
sensors_event_t event;
178
174
lis.getEvent (&event);
179
175
180
-
181
- // Detect Cube Face Orientation
176
+ // Detect cube face orientation
182
177
if (event.acceleration .x > 9 && event.acceleration .x < 10 ) // left-side up
183
178
{
184
179
// Serial.println("Cube TILTED: Left");
@@ -194,38 +189,37 @@ void loop()
194
189
cubeState = 3 ;
195
190
}
196
191
else
197
- { // orientation not found
192
+ { // orientation not specified
198
193
}
199
194
200
195
// return if the orientation hasn't changed
201
- if (cubeState == lastCubeState )
196
+ if (cubeState == prvCubeState )
202
197
return ;
203
198
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
206
200
switch (cubeState)
207
201
{
208
202
case 1 :
209
203
Serial.println (" Switching to Task 1" );
204
+ // update the neopixel strip
210
205
updatePixels (50 , 0 , 0 );
206
+ // play a sound
211
207
tone (PIEZO_PIN, 650 , 300 );
212
208
Serial.print (" Sending to Adafruit IO -> " );
213
209
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);
217
211
// reset the timer
218
212
minutes = 0 ;
219
213
break ;
220
214
case 2 :
221
215
Serial.println (" Switching to Task 2" );
216
+ // update the neopixel strip
222
217
updatePixels (0 , 50 , 0 );
218
+ // play a sound
223
219
tone (PIEZO_PIN, 850 , 300 );
224
220
Serial.print (" Sending to Adafruit IO -> " );
225
221
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);
229
223
// reset the timer
230
224
minutes = 0 ;
231
225
break ;
@@ -235,8 +229,8 @@ void loop()
235
229
break ;
236
230
}
237
231
238
- // store last cube orientation state
239
- lastCubeState = cubeState;
232
+ // save cube state
233
+ prvCubeState = cubeState;
240
234
241
235
// Delay the send to Adafruit IO
242
236
delay (sendDelay * 1000 );
0 commit comments