close-circle
Close

Sketchy Zappity Zah

A project log for Flashing Light Prize (3) Arduino Scat

Skiddily bee bop ba doo bop skiddily dee bip boop bop, yeah.

VijeMiller 07/13/2017 at 05:550 Comments
// Flashing Light Prize (3) Arduino Scat
// VijeMiller

// Sound Detector Pins
#define PIN_GATE_IN 2
#define IRQ_GATE_IN  0
#define PIN_LED_OUT 13
#define PIN_ANALOG_IN A0

// Relay Pin
int relay = 7;

// Sound Value
int val;

// SparkFun Sound Detector Interrupt
void soundISR()
{
  int pin_val;
  pin_val = digitalRead(PIN_GATE_IN);
  digitalWrite(PIN_LED_OUT, pin_val);
}

void setup()
{
  // Testing
  Serial.begin(9600);
  // Sound Detector Pin Assignment
  pinMode(PIN_LED_OUT, OUTPUT);
  pinMode(PIN_GATE_IN, INPUT);
  // Relay Pin Assignment
  pinMode(relay, OUTPUT);
  // Sound Decector Interrupt
  attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);
}

void loop()
{

  // Read Sound
  val = analogRead(PIN_ANALOG_IN);
  // Testing
  Serial.println(val);
  // If Sound Exceeds X
  if (val > 55) {
    digitalWrite(relay, HIGH);
    delay(600);
    digitalWrite(relay, LOW);
    delay(200);
  } else {
    digitalWrite(relay, LOW);
  }

  delay(10);
}

Discussions