-
Notifications
You must be signed in to change notification settings - Fork 1
/
code_microphone_light.txt
67 lines (47 loc) · 1.91 KB
/
code_microphone_light.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
Example 3
Microphone & RGB LED
Adopted idea with wiring and original code:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1277468653/
**************************************************************
Arduino code (only)
**************************************************************
int MicPin = 0; // pin that the mic is attached to
int redPin = 9; // pins that the cathodes of LED are attached to
int greenPin = 10;
int bluePin = 11;
int MicValue = 0; // the Microphone value
int t=60; // mic sensitivity - 50-90 seems optimal
void setup() {
//Serial.begin(9600); //for test the input value initialize serial
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
analogWrite(redPin, 255); //turn off all LEDs
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
}
void loop() {
MicValue = analogRead(MicPin); //read the value of the microphone
//Serial.println(MicValue); //for test the input value
if (MicValue > 530+t) { //adjust this value to the desired sensitivity
analogWrite(bluePin,0); //lights up blue
delay(15); //small delay for quick response at low noise levels
}
if (MicValue > 540+t) { //adjust this value to the desired sensitivity
analogWrite(bluePin,255); //lights up green and turn off blue
analogWrite(greenPin, 0);
delay(60); //mid delay for response at mid noise levels
}
if (MicValue > 550+t) { //adjust this value to the desired sensitivity
analogWrite(greenPin,255); //lights up red and turn off green
analogWrite(redPin, 0);
delay(140); //high delay for response at high noise levels
}
analogWrite(greenPin, 255); //Turn off all LEDs
analogWrite(redPin, 255);
analogWrite(bluePin,255);
}
analogWrite(greenPin, 255); //Turn off all LEDs
analogWrite(redPin, 255);
analogWrite(bluePin,255);
}