28
28
// Used for Pizeo
29
29
#define PIEZO_PIN 0
30
30
31
- // Pin connected to NeoPixels
32
- #define PIXELPIN 6
31
+ // NeoPixel Pin on Prop-Maker FeatherWing
32
+ #define PIN 5
33
33
34
- // Number of NeoPixels
35
- #define NUMPIXELS 16
34
+ // # of Pixels Attached
35
+ #define NUMPIXELS 8
36
+
37
+ // Library Setup
38
+ Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
36
39
37
40
// Used for software SPI
38
41
#define LIS3DH_CLK 13
44
47
// I2C
45
48
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
46
49
47
- // set up neopixel strip
48
- Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIXELPIN, NEO_GRB + NEO_KHZ800);
49
-
50
50
// Set up the 'cubeTask' feed
51
51
AdafruitIO_Feed *cubetask = io.feed(" cubetask" );
52
52
@@ -74,30 +74,42 @@ int sendDelay = 0.5;
74
74
unsigned long currentTime;
75
75
unsigned long prevTime;
76
76
int seconds = 0 ;
77
- double minutes = 0 ;
77
+ int minutes = 0 ;
78
78
79
79
void setup ()
80
80
{
81
81
// start the serial connection
82
- Serial.begin (9600 );
82
+ Serial.begin (115200 );
83
83
// wait for serial monitor to open
84
84
while (!Serial)
85
85
;
86
-
87
86
Serial.println (" Adafruit IO Time Tracking Cube" );
88
87
88
+ // disable low power mode on the prop-maker featherwing
89
+ Serial.println (" disabling low power mode..." );
90
+ pinMode (9 , INPUT);
91
+ Serial.println (" pin enabled" );
92
+ digitalWrite (9 , HIGH);
93
+ Serial.println (" pin enabled" );
94
+
89
95
// Initialize LIS3DH
90
96
if (!lis.begin (0x18 ))
91
97
{
92
- Serial.println (" Couldnt start LIS3DH " );
98
+ Serial.println (" Couldnt start" );
93
99
while (1 )
94
100
;
95
101
}
96
102
Serial.println (" LIS3DH found!" );
97
103
lis.setRange (LIS3DH_RANGE_4_G);
98
104
99
- // Initialize NeoPixel library
100
- pixels.begin ();
105
+ // enable pin 9 - turn off low power mode
106
+ // pinMode(9, OUTPUT);
107
+ // digitalWrite(9, HIGH);
108
+
109
+
110
+ // This initializes the NeoPixel library.
111
+ // pixels.begin();
112
+ Serial.println (" Pixels init'd" );
101
113
102
114
// connect to io.adafruit.com
103
115
Serial.print (" Connecting to Adafruit IO" );
@@ -113,6 +125,16 @@ void setup()
113
125
// we are connected
114
126
Serial.println ();
115
127
Serial.println (io.statusText ());
128
+
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
+ }
116
138
}
117
139
118
140
void updateTime ()
@@ -127,16 +149,6 @@ void updateTime()
127
149
}
128
150
}
129
151
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
-
140
152
void loop ()
141
153
{
142
154
// io.run(); is required for all sketches.
@@ -155,12 +167,12 @@ void loop()
155
167
// Detect Cube Face Orientation
156
168
if (event.acceleration .x > 9 && event.acceleration .x < 10 )
157
169
{
158
- Serial.println (" Cube TILTED: Left" );
170
+ // Serial.println("Cube TILTED: Left");
159
171
cubeState = 1 ;
160
172
}
161
173
else if (event.acceleration .x < -9 )
162
174
{
163
- Serial.println (" Cube TILTED: Right" );
175
+ // Serial.println("Cube TILTED: Right");
164
176
cubeState = 2 ;
165
177
}
166
178
else
@@ -175,28 +187,26 @@ void loop()
175
187
switch (cubeState)
176
188
{
177
189
case 1 :
178
- // Set pixels to green color
190
+ Serial. println ( " Switching to Task 1 " );
179
191
setPixels (0 , 150 , 0 );
180
- Serial.println (" Playing Task 1 Sound..." );
181
192
tone (PIEZO_PIN, 650 , 300 );
182
193
Serial.print (" Sending to Adafruit IO -> " );
183
- Serial.println (taskOne );
184
- cubetask->save (taskOne, minutes );
185
- Serial. println ( " Task Mins: " );
186
- Serial. println (minutes);
194
+ Serial.println (taskTwo );
195
+ cubetask->save (taskTwo );
196
+ // save previous task's minutes to a feed
197
+ cubeminutes-> save (minutes);
187
198
// reset the timer
188
199
minutes = 0 ;
189
200
break ;
190
201
case 2 :
191
- // Set pixels to red color
202
+ Serial. println ( " Switching to Task 2 " );
192
203
setPixels (150 , 0 , 0 );
193
- Serial.println (" Playing Sound 2 Sound..." );
194
204
tone (PIEZO_PIN, 850 , 300 );
195
205
Serial.print (" Sending to Adafruit IO -> " );
196
- Serial.println (taskTwo );
197
- cubetask->save (taskTwo, minutes );
198
- Serial. println ( " Task Mins: " );
199
- Serial. println (minutes);
206
+ Serial.println (taskOne );
207
+ cubetask->save (taskOne );
208
+ // save previous task's minutes to a feed
209
+ cubeminutes-> save (minutes);
200
210
// reset the timer
201
211
minutes = 0 ;
202
212
break ;
0 commit comments