g
p
// is called.
// It queries the state of that pin, and sets the onboard LED to reflect that
// pin's state.
void soundISR()
{
int pin_val;
pin_val = digitalRead(PIN_GATE_IN);
digitalWrite(PIN_LED_OUT, pin_val);
}
void setup()
{
Serial.begin(9600);
//
Configure LED pin as output
pinMode(PIN_LED_OUT, OUTPUT);
// configure input to interrupt
pinMode(PIN_GATE_IN, INPUT);
attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);
// Display status
Serial.println("Initialized");
}
void loop()
{
int value;
// Check the envelope input
value = analogRead(PIN_ANALOG_IN);
// Convert envelope value into a message
Serial.print("Status: ");
if(value <= 10)
{
Serial.println("Quiet.");
}
else if( (value > 10) && ( value <= 30) )
{
Serial.println("Moderate.");
}
else if(value > 30)
{
Serial.println("Loud.");
}
// pause for 1 second
delay(1000);
}
This code simultaneously demonstrates two different operating modes of the Sound Detector.
g
p
g
,
Need help?
Do you have a question about the SEN-12642 and is the answer not in the manual?