-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspark-neopixel.cpp~
104 lines (98 loc) · 2.24 KB
/
spark-neopixel.cpp~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* This is a minimal example, see extra-examples.cpp for a version
* with more explantory documentation, example routines, how to
* hook up your pixels and all of the pixel types that are supported.
*
*/
#include "application.h"
//#include "spark_disable_wlan.h" // For faster local debugging only
#include "neopixel.h"
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN A1
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812B
#define R1[450] {0, 1}
#define R2[450] {0, 1}
#define R3[450] {0, 1}
#define MR[450] {0, 1}
#define ML[450] {0, 1}
#define L1[450] {0, 1}
#define L2[450] {0, 1}
#define L3[450] {0, 1}
int color1;
int color2;
int color3;
int color4;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
void setup()
{
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Spark.variable("color1", &color1, INT);
Spark.variable("color2", &color2, INT);
Spark.variable("color3", &color3, INT);
Spark.variable("color4", &color4, INT);
Spark.function("right", right);
Spark.function("left", left);
Spark.function("reg", reg);
Spark.function("stop", stop);
}
void loop()
{
strip.setBrightness(100);
rainbow(20);
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
color1=strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
return color1;
} else if(WheelPos < 170) {
WheelPos -= 85;
color2= strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
return color2;
} else {
WheelPos -= 170;
color3=strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
return color3;
}
}
void left(){
color1=strip.Color(0, 0, 255);
strip.setPixelColor(0, color1 & 255);
strip.show();
delay(wait);
delay(1000);
}
void right(){
color2=strip.Color(0, 255, 0);
strip.setPixelColor(0, color2 & 255);
strip.show();
delay(wait);
delay(1000);
}
void reg(){
color3=strip.Color(255, 0, 0);
strip.setPixelColor(0, color3 & 255);
strip.show();
delay(wait);
delay(1000);
}
void stop(){
color4=strip.Color(255, 255, 255);
strip.setPixelColor(0, color4 & 255);
strip.show();
delay(wait);
delay(1000);
}