Skip to content

Commit 2d2d08f

Browse files
author
brentru
committed
two-face tasks with neopixel
1 parent 3af3222 commit 2d2d08f

File tree

1 file changed

+47
-37
lines changed

1 file changed

+47
-37
lines changed

examples/adafruitio_24_zapier/adafruitio_24_zapier.ino

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
// Used for Pizeo
2929
#define PIEZO_PIN 0
3030

31-
// Pin connected to NeoPixels
32-
#define PIXELPIN 6
31+
// NeoPixel Pin on Prop-Maker FeatherWing
32+
#define PIN 5
3333

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);
3639

3740
// Used for software SPI
3841
#define LIS3DH_CLK 13
@@ -44,9 +47,6 @@
4447
// I2C
4548
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
4649

47-
// set up neopixel strip
48-
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIXELPIN, NEO_GRB + NEO_KHZ800);
49-
5050
// Set up the 'cubeTask' feed
5151
AdafruitIO_Feed *cubetask = io.feed("cubetask");
5252

@@ -74,30 +74,42 @@ int sendDelay = 0.5;
7474
unsigned long currentTime;
7575
unsigned long prevTime;
7676
int seconds = 0;
77-
double minutes = 0;
77+
int minutes = 0;
7878

7979
void setup()
8080
{
8181
// start the serial connection
82-
Serial.begin(9600);
82+
Serial.begin(115200);
8383
// wait for serial monitor to open
8484
while (!Serial)
8585
;
86-
8786
Serial.println("Adafruit IO Time Tracking Cube");
8887

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+
8995
// Initialize LIS3DH
9096
if (!lis.begin(0x18))
9197
{
92-
Serial.println("Couldnt start LIS3DH");
98+
Serial.println("Couldnt start");
9399
while (1)
94100
;
95101
}
96102
Serial.println("LIS3DH found!");
97103
lis.setRange(LIS3DH_RANGE_4_G);
98104

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");
101113

102114
// connect to io.adafruit.com
103115
Serial.print("Connecting to Adafruit IO");
@@ -113,6 +125,16 @@ void setup()
113125
// we are connected
114126
Serial.println();
115127
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+
}
116138
}
117139

118140
void updateTime()
@@ -127,16 +149,6 @@ void updateTime()
127149
}
128150
}
129151

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-
140152
void loop()
141153
{
142154
// io.run(); is required for all sketches.
@@ -155,12 +167,12 @@ void loop()
155167
// Detect Cube Face Orientation
156168
if (event.acceleration.x > 9 && event.acceleration.x < 10)
157169
{
158-
Serial.println("Cube TILTED: Left");
170+
//Serial.println("Cube TILTED: Left");
159171
cubeState = 1;
160172
}
161173
else if (event.acceleration.x < -9)
162174
{
163-
Serial.println("Cube TILTED: Right");
175+
//Serial.println("Cube TILTED: Right");
164176
cubeState = 2;
165177
}
166178
else
@@ -175,28 +187,26 @@ void loop()
175187
switch (cubeState)
176188
{
177189
case 1:
178-
// Set pixels to green color
190+
Serial.println("Switching to Task 1");
179191
setPixels(0, 150, 0);
180-
Serial.println("Playing Task 1 Sound...");
181192
tone(PIEZO_PIN, 650, 300);
182193
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);
187198
// reset the timer
188199
minutes = 0;
189200
break;
190201
case 2:
191-
// Set pixels to red color
202+
Serial.println("Switching to Task 2");
192203
setPixels(150, 0, 0);
193-
Serial.println("Playing Sound 2 Sound...");
194204
tone(PIEZO_PIN, 850, 300);
195205
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);
200210
// reset the timer
201211
minutes = 0;
202212
break;

0 commit comments

Comments
 (0)