NeoPixel_without_Delay
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 |
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
const int com_num = 9;
int com = 0;
long led_count = 0;
unsigned long time_ms;
void setup() {
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
switch(com) {
case 0:
colorWipe(strip.Color(255, 0, 0), 50); // Red
break;
case 1:
colorWipe(strip.Color(0, 255, 0), 50); // Green
break;
case 2:
colorWipe(strip.Color(0, 0, 255), 50); // Blue
break;
case 3:
theaterChase(strip.Color(127, 127, 127), 50); // White
break;
case 4:
theaterChase(strip.Color(127, 0, 0), 50); // Red
break;
case 5:
theaterChase(strip.Color(0, 127, 0), 50); // Green
break;
case 6:
theaterChase(strip.Color(0, 0, 127), 50); // Blue
break;
case 7:
rainbow(20);
break;
case 8:
rainbowCycle(20);
break;
case 9:
theaterChaseRainbow(50);
break;
}
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
if(millis() > time_ms + wait) {
time_ms = millis();
strip.setPixelColor(led_count, c);
strip.show();
led_count++;
if(led_count>=strip.numPixels()) {
led_count = 0;
com++;
if(com > com_num) {
com = 0;
}
}
}
}
void rainbow(uint8_t wait) {
if(millis() > time_ms + wait) {
time_ms = millis();
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+led_count) & 255));
}
strip.show();
led_count++;
if(led_count>=256) {
led_count = 0;
com++;
if(com > com_num) {
com = 0;
}
}
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
if(millis() > time_ms + wait) {
time_ms = millis();
for(uint16_t i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + led_count) & 255));
}
strip.show();
led_count++;
if(led_count>=256*5) {
led_count = 0;
com++;
if(com > com_num) {
com = 0;
}
}
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
if(millis() > time_ms + wait) {
time_ms = millis();
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+(led_count%3), c); //turn every third pixel on
}
strip.show();
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+(led_count%3), 0); //turn every third pixel off
}
led_count++;
if(led_count>=10*3) {
led_count = 0;
com++;
if(com > com_num) {
com = 0;
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
if(millis() > time_ms + wait) {
time_ms = millis();
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+(led_count%3), Wheel( (i+(led_count/3)) % 255)); //turn every third pixel on
}
strip.show();
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+(led_count%3), 0); //turn every third pixel off
}
led_count++;
if(led_count>=256*3) {
led_count = 0;
com++;
if(com > com_num) {
com = 0;
}
}
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
|
cs |
'Study > 아두이노( Arduino)' 카테고리의 다른 글
ATMEGA64M1 Arduino Bootloader (0) | 2021.11.03 |
---|---|
AST-CAN 부트로더 구울때 에러 (0) | 2019.11.13 |
NeoPixel 구동에 필요한 최소 소스코드 (0) | 2018.04.02 |
조도 센서(Adafruit Lux Sensor TSL2561) 예제 소스 (0) | 2018.03.31 |