-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduinoFX.txt
187 lines (149 loc) · 3.5 KB
/
ArduinoFX.txt
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
/*These are like the import statements in java except instead
* of holding the actual implementation of the code they hold the declerations in C++ header files which we can access for our own uses.
* It litteraly dumps all the code from the other class we want
* Ex. We could litteraly does this:
* int i =
* #include <valueofpi.h>
* ;
* In the acutal valueofpi.h file we can litteraly just have 3.14 by itself.
* This shows how it is litteraly just copying and pasting the code into our file
*
* If we have written it ourselves instead of <> we use ""
* Ex. #include "SoftwareSerial.h"
*
* The include directive always has to be on its own line
*/
#include <SoftwareSerial.h> //This is part of the Arduino library
#include <BlynkSimpleStream.h>
#include <stdlib.h>
SoftwareSerial SerialDebugger(2,3);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "fKN7KAuYKjf0OTN3Yy1YyWcxC2HbqUn_";
int currentEffect = 0;
char response = 0;
int mSpeed = 1;
bool staticColorChange = false;
bool smoothRainbow = false;
int fadeRed;
int fadeGreen;
int fadeBlue;
int fadeRedTarget = 255;
int fadeGreenTarget = 255;
int fadeBlueTarget = 255;
void setup()
{
// Blynk will work through Serial
Serial.begin(9600);
SerialDebugger.begin(9600);
pinMode(2, INPUT);
pinMode(3, OUTPUT);
Blynk.begin(Serial ,auth);
}
void loop()
{
Blynk.run();
while(staticColorChange)
{
if(millis() % (5000/mSpeed) == 0)
{
analogWrite(9 , rand() % 256);
analogWrite(10 , rand() % 256);
analogWrite(11 , rand() % 256);
}
Blynk.run();
}
while(smoothRainbow)
{
if(millis() % (100/mSpeed) == 0)
{
changeRGBVals();
analogWrite(9 , fadeBlue);
analogWrite(10 , fadeRed);
analogWrite(11 , fadeGreen);
Serial.println(fadeRed);
Serial.println(fadeBlue);
Serial.println(fadeGreen);
}
Blynk.run();
}
}
//This is for the Color Picker
BLYNK_WRITE(V0)
{
staticColorChange = false;
smoothRainbow = false;
analogWrite(9 ,param[2].asInt());
analogWrite(10 ,param[0].asInt());
analogWrite(11 ,param[1].asInt());
}
//This is for the Effect Picker
BLYNK_WRITE(V1)
{
if(param.asInt() == 2)
{
smoothRainbow = false;
staticColorChange = true;
}
else if(param.asInt() == 3)
{
staticColorChange = false;
smoothRainbow = true;
fadeRedTarget = rand() % 256;
fadeGreenTarget = rand() % 256;
fadeBlueTarget = rand() % 256;
}
}
//This is for the speed adjuster
BLYNK_WRITE(V2)
{
if(mSpeed == 0)
{
mSpeed = 1;
}
else if(mSpeed == 51)
{
mSpeed = 50;
}
mSpeed += param.asInt();
}
//This changes the RGB values for the smootheRainbow Effect
void changeRGBVals()
{
if(fadeRed > fadeRedTarget)
{
fadeRed--;
}
else if(fadeRed < fadeRedTarget)
{
fadeRed++;
}
if(fadeGreen > fadeGreenTarget)
{
fadeGreen--;
}
else if(fadeGreen < fadeGreenTarget)
{
fadeGreen++;
}
if(fadeBlue > fadeBlueTarget)
{
fadeBlue--;
}
else if(fadeBlue < fadeBlueTarget)
{
fadeBlue++;
}
if(fadeRed == fadeRedTarget)
{
fadeRedTarget = rand() % 256;
}
if(fadeGreen == fadeGreenTarget)
{
fadeGreenTarget = rand() % 256;
}
if(fadeBlue == fadeBlueTarget)
{
fadeBlueTarget = rand() % 256;
}
}