-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsketch_oct14a.ino
217 lines (169 loc) · 4.53 KB
/
sketch_oct14a.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
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
#include <FastLED.h>
// MicNakano ***************************************************************
int MicSensorValue = 0;
const int MicMicPin = 13;
const int MicLedPin = 21;
int MicSensMin = 4095;
int MicSensMax = 0;
int MicLedState = LOW;
long MicPreviousMillis = 0;
int MicMillisOn = 0;
// YK04 ********************************************************************
const int RFRight = 18;
const int RFLeft = 19;
int RFLedState1 = LOW;
int RFLedState2 = LOW;
int RFLedState3 = LOW;
unsigned long RFPreviousMillis1 = 0;
unsigned long RFPreviousMillis2 = 0;
int RFMillisOn1 = 0;
int RFMillisOn2 = 0;
const long iterations = 1500;
const long blinkInterval = 100;
#define NUM_LEDS 24
#define NUM_LEDS2 4
#define DATA_PIN 4
#define DATA_PIN2 15
CRGB leds[NUM_LEDS];
CRGB leds2[NUM_LEDS2];
void led(int side, int state) { // Side: 0 = Right, 1 = Left. State: HIGH = On, LOW = Off
byte i, j, r, g, b;
if (side == 0) {
i = 0; // Beginning of the strip
j = NUM_LEDS / 2; // Half of the strip
if (state == HIGH) {
r = 255;
g = 45;
b = 0;
RFLedState1 == HIGH;
} else {
r = 0;
g = 0;
b = 0;
RFLedState1 == LOW;
}
} else {
i = NUM_LEDS / 2; // Half of the strip
j = NUM_LEDS; // End of the strip
if (state == HIGH) {
r = 255;
g = 45;
b = 0;
RFLedState2 == HIGH;
} else {
r = 0;
g = 0;
b = 0;
RFLedState2 == LOW;
}
}
for (int cur = i; cur < j; cur++) {
leds[cur] = CRGB(r, g, b);
}
FastLED.show();
}
void ledMic(int state) {
byte i, j, r, g, b;
i = 0;
j = 4;
if (state == HIGH) {
r = 255;
g = 45;
b = 0;
RFLedState3 == HIGH;
} else {
r = 0;
g = 0;
b = 0;
RFLedState3 == LOW;
}
for (int cur = i; cur < j; cur++) {
leds2[cur] = CRGB(r, g, b);
}
FastLED.show();
}
void setup() {
Serial.begin(115200);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, DATA_PIN2>(leds2, NUM_LEDS2);
pinMode(MicLedPin, OUTPUT);
analogReadResolution(12);
pinMode(RFRight, INPUT);
pinMode(RFLeft, INPUT);
}
void loop() {
// Mic ********************************************************************
// read the analog / millivolts value for MicLedPin:
MicSensorValue = analogRead(MicMicPin);
MicSensMin = (MicSensorValue < MicSensMin) ? MicSensorValue : MicSensMin;
MicSensMax = (MicSensorValue > MicSensMax) ? MicSensorValue : MicSensMax;
if (MicSensorValue > 2300) {
MicMillisOn = iterations;
}
if (MicMillisOn != 0) {
unsigned long MicCurrentMillis = millis();
if (MicCurrentMillis - MicPreviousMillis > blinkInterval) {
// save the last time you blinked the LED
MicPreviousMillis = MicCurrentMillis;
// if the LED is off turn it on and vice-versa:
if (MicLedState == LOW)
MicLedState = HIGH;
else
MicLedState = LOW;
// set the LED with the MicLedState of the variable:
ledMic(MicLedState);
}
--MicMillisOn;
} else {
ledMic(LOW);
}
Serial.print(MicSensorValue);
Serial.print(" ");
Serial.print(MicSensMin);
Serial.print(" ");
Serial.println(MicSensMax);
// Right RF ***************************************************************
if(digitalRead(RFRight) > 0) {
RFMillisOn1 = iterations;
}
Serial.println(RFMillisOn1);
if (RFMillisOn1 > 0) {
unsigned long RFcurrentMillis1 = millis();
if (RFcurrentMillis1 - RFPreviousMillis1 >= blinkInterval) {
// save the last time you blinked the LED
RFPreviousMillis1 = RFcurrentMillis1;
// if the LED is off turn it on and vice-versa:
if (RFLedState1 == LOW)
RFLedState1 = HIGH;
else
RFLedState1 = LOW;
// set the LED with the MicLedState of the variable:
led(0, RFLedState1);
}
--RFMillisOn1;
} else {
led(0, LOW);
}
// Left RF ****************************************************************
if(digitalRead(RFLeft) > 0) {
RFMillisOn2 = iterations;
}
Serial.println(RFMillisOn2);
if (RFMillisOn2 > 0) {
unsigned long RFcurrentMillis2 = millis();
if (RFcurrentMillis2 - RFPreviousMillis2 > blinkInterval) {
// save the last time you blinked the LED
RFPreviousMillis2 = RFcurrentMillis2;
// if the LED is off turn it on and vice-versa:
if (RFLedState2 == LOW)
RFLedState2 = HIGH;
else
RFLedState2 = LOW;
// set the LED with the MicLedState of the variable:
led(1, RFLedState2);
}
--RFMillisOn2;
} else {
led(1, LOW);
}
}