-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfinitMirror.ino
140 lines (132 loc) · 3.12 KB
/
infinitMirror.ino
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
#include <Adafruit_NeoPixel.h>
#include "stdlib.h"
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN D5
#define NUMPIXELS 45
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 200
void setup()
{
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
pixels.setBrightness(250);
pixels.begin();
}
//三种颜色显示切换效果
char targetNumA = 0;
char targetNumB = 1;
char targetNumC = 2;
void modelRGB(int repeatTimes)
{
for (int t = 0; t < repeatTimes; t++)
{
pixels.clear();
for (int i = 0; i < NUMPIXELS; i++)
{
if (i % 3 == targetNumA)
{
pixels.setPixelColor(i, getRandomColor());
}
else if (i % 3 == targetNumB)
{
pixels.setPixelColor(i, getRandomColor());
}
else if (i % 3 == targetNumC)
{
pixels.setPixelColor(i, getRandomColor());
}
}
if (targetNumA == 0)
{
targetNumA = 1;
targetNumB = 2;
targetNumC = 0;
}
else if (targetNumA == 1)
{
targetNumA = 2;
targetNumB = 0;
targetNumC = 1;
}
else if (targetNumA == 2)
{
targetNumA = 0;
targetNumB = 1;
targetNumC = 2;
}
pixels.show();
delay(300);
}
}
uint32_t getRandomColor()
{
return pixels.Color((rand() % 255 + 1), (rand() % 255 + 1), (rand() % 255 + 1));
}
//随机颜色转圈圈效果
void modelCircle(bool isSeq, int repeatTimes)
{
for (int t = 0; t < repeatTimes; t++)
{
pixels.clear();
for (int i = 0; i < NUMPIXELS; i++)
{
if (isSeq == false && i % 5 == 0)
{
pixels.clear();
}
pixels.setPixelColor(i, getRandomColor());
pixels.show();
delay(50);
}
}
}
//随机显示20颗随机颜色效果
void modelRandom(int repeatTimes)
{
for (int t = 0; t < repeatTimes; t++)
{
pixels.clear();
//随即闪烁20个单体led 然后全体闪烁3次
for (int i = 0; i < 20; i++)
{
int randLed = rand() % NUMPIXELS + 1;
pixels.setPixelColor(randLed, getRandomColor());
pixels.show();
delay(50);
}
pixels.clear();
//全体闪烁
for (int a = 0; a < 3; a++)
{
for (int i = 0; i < NUMPIXELS; i++)
{
pixels.setPixelColor(i, getRandomColor());
}
pixels.show();
delay(300);
pixels.clear();
}
}
}
//随机显示20颗随机颜色效果
void showPureColor(uint32_t color, int delayTime)
{
pixels.clear();
for (int i = 0; i < NUMPIXELS; i++)
{
pixels.setPixelColor(i, color);
}
pixels.show();
delay(delayTime);
}
void loop()
{
//颜色切换显示效果
modelRGB(12);
modelRandom(3);
modelCircle(true, 3);
showPureColor(getRandomColor(),3000);
}