-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecibelcheckandrecord.ino
75 lines (64 loc) · 1.38 KB
/
decibelcheckandrecord.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
#define PIN_GATE_IN 2 // DB chekcer
#define IRQ_GATE_IN 0 // DB checker
#define PIN_LED_OUT 13 // DB checker
#define PIN_ANALOG_IN A0 // DB checker
int REC = 8; // recorder
int PLAYE = 9; // recorder
char input = 0; // recorder
void soundISR() // DB checker
{
int pin_val;
pin_val = digitalRead(PIN_GATE_IN);
digitalWrite(PIN_LED_OUT, pin_val);
}
void setup()
{
Serial.begin(9600);
pinMode(REC,OUTPUT); // Recorder
pinMode(PLAYE,OUTPUT); // Recorder
pinMode(PIN_LED_OUT, OUTPUT); // DB checker LED OUTPUT
pinMode(PIN_GATE_IN, INPUT); // DB checker
attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE); //DB checker
Serial.println("Initialized"); // DB checker Initialized
}
void loop()
{
// DB checker from here
int value; // DB checker
value = analogRead(PIN_ANALOG_IN);
Serial.print(value);
Serial.print("Status: ");
if(value <= 100)
{
Serial.println("Quiet.");
}
else if( (value > 100) && ( value <= 300) )
{
Serial.println("Moderate.");
}
else if(value > 300)
{
Serial.println("Loud.");
}
delay(1000);
// recorder from here
while(Serial.available()){
input = Serial.read();
if(value>300)
input='P'; // when loud
switch(input){
case 'R':
digitalWrite(REC,HIGH);
break;
case 'S':
digitalWrite(REC,LOW);
break;
case 'P':
digitalWrite(PLAYE,HIGH);
delay(10);
digitalWrite(PLAYE,LOW);
break;
}
}
}
//egg