-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneopixel.c
172 lines (149 loc) · 4.66 KB
/
neopixel.c
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(20, 6, NEO_GRB + NEO_KHZ800);
#include "Arduino.h"
#include "neopixel.h"
int MinBrightness = 1; //value 0-255
int MaxBrightness = 50; //value 0-255
int numLoops1 = 10;
int numLoops2 = 5;
//int numLoops3 = 5;
//int numLoops4 = 3; //add new integer and value for more color's loop if needed.
int fadeInWait = 30; //lighting up speed, steps.
int fadeOutWait = 50; //dimming speed, steps.
const int num = 20;
const int pin = 6;
void neopixcel_init(){
strip.begin();
strip.clear();
strip.setBrightness(255);
}
void ON_LED(const int R, const int G, const int B){
for (int j =0; j < strip.numPixels(); j++) {
strip.setPixelColor(j, strip.Color(R, G, B));
strip.show();
}
}
void rainbowBreathe(uint8_t x, uint8_t y) {
for (int j = 0; j < x; j++) {
for (uint8_t b = MinBrightness; b < MaxBrightness; b++) {
strip.setBrightness(b * 255 / 255);
for (uint8_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(i * 256 / strip.numPixels()));
}
strip.show();
delay(fadeInWait);
}
strip.setBrightness(MaxBrightness * 255 / 255);
for (uint8_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(i * 256 / strip.numPixels()));
strip.show();
delay(y);
}
for (uint8_t b = MaxBrightness; b > MinBrightness; b--) {
strip.setBrightness(b * 255 / 255);
for (uint8_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(i * 256 / strip.numPixels()));
}
strip.show();
delay(fadeOutWait);
}
}
}
void rgbBreathe(uint32_t c, uint8_t x, uint8_t y) {
for (int j = 0; j < x; j++) {
for (uint8_t b = MinBrightness; b < MaxBrightness; b++) {
strip.setBrightness(b * 255 / 255);
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
delay(fadeInWait);
}
strip.setBrightness(MaxBrightness * 255 / 255);
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(y);
}
for (uint8_t b = MaxBrightness; b > MinBrightness; b--) {
strip.setBrightness(b * 255 / 255);
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
}
strip.show();
delay(fadeOutWait);
}
}
}
//NeoPixel에 달린 LED를 각각 주어진 인자값 색으로 채워나가는 함수
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
//모든 LED를 출력가능한 모든색으로 한번씩 보여주는 동작을 한번하는 함수
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);
}
}
//NeoPixel에 달린 LED를 각각 다른색으로 시작하여 다양한색으로 5번 반복한다
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) {
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
//입력한 색으로 LED를 깜빡거리며 표현한다
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//LED를 다양한색으로 표현하며 깜빡거린다
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { //256가지의 색을 표현
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255));
}
strip.show();
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0);
}
}
}
}
//255가지의 색을 나타내는 함수
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}