/*
P02_Collision_Experiment
Crowtail - collision sensor connect to D3 port
Crowtail - led connect to D5 port
Crowtail - buzzer connect to D6 port
*/

#define collisionPin 3
#define ledPin 5
#define buzzerPin 6

int collisionState = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin,OUTPUT);
  pinMode(buzzerPin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  collisionState = digitalRead(collisionPin);
  // if collision is detected, collisionState is LOW
  if(collisionState == LOW)
  {  
     // make a blinking led and noise
     digitalWrite(ledPin,HIGH);
     digitalWrite(buzzerPin,HIGH);
     delay(500);
     digitalWrite(ledPin,LOW);
     digitalWrite(buzzerPin,LOW);
     delay(200);
    }
    // if collision is not detected, collisionState is HIGH
    else
    {
      digitalWrite(ledPin,LOW);
      digitalWrite(buzzerPin,LOW);
      }
}
