This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
forked from iddofroom/Independence_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFireWork_Basic
256 lines (224 loc) · 6.54 KB
/
FireWork_Basic
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#include "SoftwareSerial.h"
#include <FastLED.h>
FASTLED_USING_NAMESPACE
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
# define ACTIVATED LOW
#define DATA_PIN 3
//#define CLK_PIN 4
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 100
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 96
#define FRAMES_PER_SECOND 60
int indicator = 13; // LED
int sensorPin = 5; // PIR Out pin
int pirStat = 0; // PIR status
uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
boolean isPlaying = true;
void setup () {
mySerial.begin (9600);
delay(1000);
execute_CMD(0x3F, 0, 0);
delay(500);
setVolume(28);
delay(500);
execute_CMD(0x11,0,1);
delay(500);
isPlaying = false;
pinMode(indicator, OUTPUT);
pinMode(sensorPin, INPUT);
Serial.begin(9600);
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
pause();
}
void loop(){
byte state = digitalRead(sensorPin);
digitalWrite(indicator,state);
//if(state != 1)
// {
playFirst();
Serial.println("Somebody is in this area!");
Lunch(255,255,255);
Boom(255,0,0);
FireWorks1();
// }
delay(2000);
}
//---------------Led FireWorks Strips -------------
int ledCurraction(int number, int StripNumber){
int Strip2[] = {25,49,26,48,27,47,28,46,29,45,30,44,31,43,32,42,33,41,34,40,35,39,35,38,37};
int Strip1[] ={0,24,1,23,2,22,3,21,4,20,5,19,6,18,7,17,8,16,8,15,10,14,11,13,12};
int Mainstrip[] = {0,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};
if (StripNumber==1){return Mainstrip[number-1];}
else if (StripNumber==2){return Strip1[number-1]+50;}
else if (StripNumber==3){return Strip2[number-1]+50;}
}
void Lunch(int r, int g , int b){
for (int i=0;i<48;i++)
{
if (i>0){leds[i-1] = CRGB(0,0,0);}
leds[i] = CRGB(r,g,b);
leds[i+1] = CRGB(r,g,b);
leds[i+2] = CRGB(r,g,b);
FastLED.show();
if (i<40)
{ FastLED.delay(20);}
else
{FastLED.delay(20+(i-40)*20);}
}
leds[47] = CRGB(0,0,0);
FastLED.show();
FastLED.delay(20);
leds[48] = CRGB(0,0,0);
FastLED.show();
FastLED.delay(20);
leds[49] = CRGB(0,0,0);
leds[50] = CRGB(0,0,0);
FastLED.show();
FastLED.delay(100);
}
void Boom(int r, int g , int b){
leds[ledCurraction(1,2)] = CRGB(r,g,b);
leds[ledCurraction(1,3)] = CRGB(r,g,b);
FastLED.show();
FastLED.delay(40);
leds[ledCurraction(2,2)] = CRGB(r,g,b);
leds[ledCurraction(2,3)] = CRGB(r,g,b);
FastLED.show();
FastLED.delay(40);
leds[ledCurraction(3,2)] = CRGB(r,g,b);
leds[ledCurraction(3,3)] = CRGB(r,g,b);
FastLED.show();
FastLED.delay(40);
for (int i=1;i<30;i++)
{
leds[ledCurraction(1,2)] = CRGB(r-30*i,g,b);
leds[ledCurraction(1,3)] = CRGB(r-30*i,g,b);
leds[ledCurraction(2,2)] = CRGB(r-30*i,g,b);
leds[ledCurraction(2,3)] = CRGB(r-30*i,g,b);
leds[ledCurraction(3,2)] =CRGB(r-30*i,g,b);
leds[ledCurraction(3,3)] = CRGB(r-30*i,g,b);
FastLED.show();
FastLED.delay(10);
}
for (int i=1;i<52;i++)
{
leds[ledCurraction(1,2)]= CRGB(r-5*i,g,b);
leds[ledCurraction(1,3)] = CRGB(r-5*i,g,b);
leds[ledCurraction(2,2)] = CRGB(r-5*i,g,b);
leds[ledCurraction(2,3)] = CRGB(r-5*i,g,b);
leds[ledCurraction(3,2)] = CRGB(r-5*i,g,b);
leds[ledCurraction(3,3)] = CRGB(r-5*i,g,b);
FastLED.show();
FastLED.delay(10);
}
FastLED.delay(100);
}
void FireWorks1(){
for (int i=1;i<26;i++)
{
leds[ledCurraction(i,2)] = CRGB(0,255,0);
leds[ledCurraction(i,3)] = CRGB(255,0,0);
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(i*3);
}
pause(); /// Stop The Audio-----------------------------------
leds[ledCurraction(25,2)] = CRGB(0,255,0);
leds[ledCurraction(25,3)] = CRGB(255,0,0);
// send the 'leds' array out to the actual LED strip
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(1000/FRAMES_PER_SECOND);
for (int i=1;i<3;i++)
{
for (int j=1;j<40;j++)
{
for (int l=1;l<26;l++)
{
leds[ledCurraction(l,2)] = CRGB(0,250-j*4,0);
leds[ledCurraction(l,3)] = CRGB(250-j*4,0,0);
}
FastLED.show();
FastLED.delay(5);
}
for (int j=1;j<40;j++)
{
for (int l=1;l<26;l++)
{
leds[ledCurraction(l,2)] = CRGB(0,90+j*4,0);
leds[ledCurraction(l,3)] = CRGB(90+j*4,0,0);
}
FastLED.show();
FastLED.delay(5);
}
}
for (int i=1;i<26;i++)
{
leds[ledCurraction(i,2)] = CRGB(0,0,0);
leds[ledCurraction(i,3)] = CRGB(0,0,0);
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(50);
}
leds[ledCurraction(25,2)] = CRGB(0,0,0);
leds[ledCurraction(25,3)] = CRGB(0,0,0);
// send the 'leds' array out to the actual LED strip
FastLED.show();
// insert a delay to keep the framerate modest
FastLED.delay(1000/FRAMES_PER_SECOND);
}
//---------------Audio Functions -------------
void playFirst()
{
execute_CMD(0x3F, 0, 0);
delay(500);
setVolume(27);
delay(500);
execute_CMD(0x11, 0, 1);
delay(500);
}
void play()
{
execute_CMD(0x0D,0,1);
delay(500);
}
void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
mySerial.write( Command_line[k]);
}
}
void setVolume(int volume)
{
execute_CMD(0x06, 0, volume); // Set the volume (0x00~0x30)
delay(2000);
}
void pause()
{
execute_CMD(0x0E,0,0);
delay(500);
}
void playNext()
{
execute_CMD(0x01,0,1);
delay(500);
}