Skip to content

Commit 0db55cd

Browse files
author
Bonnie Barrilleaux
committed
add arduino code
1 parent 787b197 commit 0db55cd

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//LED code for Nagaliers. Changes your lighting based on your activity level logged by Fitbit.
2+
/*************************************************************************************/
3+
4+
#include "FastSPI_LED2.h"
5+
#define NUM_LEDS 60
6+
7+
struct CRGB leds[NUM_LEDS];
8+
int colorval = 0; // Variable to hold the changing "mood light" strip color.
9+
int steps=0;
10+
11+
void setup() {
12+
LEDS.setBrightness(250);
13+
LEDS.addLeds<WS2811, 5>(leds, NUM_LEDS);
14+
Serial.begin(9600);
15+
}
16+
17+
18+
void loop() {
19+
//get the step count
20+
if (Serial.available() > 0) {
21+
steps = Serial.read();
22+
}
23+
//light up the strip!
24+
if(steps==255) rainbow(colorval % 384); //if you've met your step goal
25+
else if(steps==0) angryFlash(); // if you're behind schedule
26+
else RGBcolorFill(steps); // if you're making progress
27+
colorval++; // increment the color for the reward rainbow when you've met step goals.
28+
}
29+
30+
31+
//Fill the strip with 1/3 of a rainbow, starting from color c
32+
void rainbow(uint32_t c) {
33+
uint16_t i;
34+
for (i=0; i < NUM_LEDS; i++) {
35+
leds[i] = RGBWheel(((i * 128 / NUM_LEDS) + c) % 384); // 128 = 384/3 = 1/3 of the rainbow.
36+
}
37+
LEDS.show();
38+
}
39+
40+
// Fill the strip with a single color.
41+
void RGBcolorFill(uint32_t c) {
42+
int i;
43+
c = map(c, 0, 255, 0, 300);
44+
for (i=0; i < NUM_LEDS; i++) {
45+
leds[i] = RGBWheel(c); // set all active pixels on
46+
}
47+
LEDS.show();
48+
}
49+
50+
// Flash red.
51+
void angryFlash() {
52+
int i;
53+
//Turn strip red.
54+
for (i=0; i < NUM_LEDS; i++) {
55+
leds[i] = CRGB(0, 255, 0); // set all active pixels red
56+
}
57+
LEDS.show();
58+
delay(100);
59+
//Turn strip off.
60+
for (int i=0; i < NUM_LEDS; i++) {
61+
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB));
62+
}
63+
LEDS.show();
64+
delay(100);
65+
}
66+
67+
/* RGB Color Wheel Helper function */
68+
//Input a value 0 to 384 to get a color value.
69+
CRGB RGBWheel(uint16_t WheelPos) {
70+
byte r, g, b;
71+
switch(WheelPos / 128)
72+
{
73+
case 0:
74+
r = 127 - WheelPos % 128; // red down
75+
g = WheelPos % 128; // green up
76+
b = 0; // blue off
77+
break;
78+
case 1:
79+
g = 127 - WheelPos % 128; // green down
80+
b = WheelPos % 128; // blue up
81+
r = 0; // red off
82+
break;
83+
case 2:
84+
b = 127 - WheelPos % 128; // blue down
85+
r = WheelPos % 128; // red up
86+
g = 0; // green off
87+
break;
88+
}
89+
return(CRGB(b, r, g)); //colors are in a stupid order.
90+
}
91+
92+

0 commit comments

Comments
 (0)