Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int analogValue; // This is where we'll store our audio to digital value. More sound = higher number
- int LED_Pin = 13; // Set up the LED indicator
- int Sound_Pin = A0;
- boolean toggle = false; // setup a boolean function called toggle which will help us to choose which mode we're in
- int t =548 ;
- void setup()
- {
- pinMode(LED_Pin,OUTPUT); // Pin#5 should be conencted to an LED through a 300-600 ohm resistor
- Serial.begin(9600); // This is optional - It just helps you to calibrate sensitivity after the fact
- }
- void loop()
- {
- /*analogValue = analogRead(Sound_Pin);
- Serial.println(analogValue);
- delay(50);*/
- if (toggle == false) // When you power up your arduino, boolean "toggle" is set to false, so the following section of code will commence. The "ELSE" is ignored for now.
- {
- digitalWrite(LED_Pin,LOW); // Turn the LED off
- analogValue = analogRead(Sound_Pin); // Take an analog reading from A0 line. No sounds should be offer a returned value of "0"
- if (analogValue >t) // If higher than 8 is returned, then change state of boolean "toggle" to true, display analogValue to serial monitor and wait 200ms.
- // The higher the value in the above "if" statement, the less sensitive your clapper will be. Use the serial monitor to calibrate to your wanted sensitivity =D
- {
- toggle = true;
- Serial.println(analogValue);
- delay(200);
- }
- }
- else // If boolean "toggle" has beenchanged to true, then the above section of code will be ignored, and the code below will commence.
- {
- digitalWrite(LED_Pin,HIGH); // Turn the LED on
- analogValue = analogRead(0); // Take an analog reading from A0 line. No sounds should be offer a returned value of "0"
- if (analogValue > t) // If higher than 8 is returned, then change state of boolean "toggle" back to false, print analogValue to serial monitor and wait 200ms.
- // The higher the value in the above "if" statement, the less sensitive your clapper will be. Use the serial monitor to calibrate to your wanted sensitivity =D
- {
- toggle = false;
- Serial.println(analogValue);
- delay(200);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement