Created
March 17, 2017 20:19
-
-
Save anonymous/d5d01ec8fb3de77345e46e57066528ed to your computer and use it in GitHub Desktop.
Project 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PIN_GATE_IN A0 | |
int ledPinGreen = 10; | |
int ledPinYellow = 11; | |
int ledPinRed = 12; | |
void setup() { | |
Serial.begin(9600); | |
// sound detector setup | |
pinMode(ledPinRed, OUTPUT); | |
pinMode(ledPinYellow, OUTPUT); | |
pinMode(ledPinGreen, OUTPUT); | |
pinMode(PIN_GATE_IN, INPUT); | |
// Display status | |
Serial.println("Initialized"); | |
} | |
void loop() { | |
// sound detector loop | |
int value; | |
// Check the gate input | |
value = analogRead(PIN_GATE_IN); | |
// Convert gate value into a message | |
Serial.print("Value: "); | |
if (value <= 315) { | |
digitalWrite(ledPinGreen, LOW); //LOW turns on the LEDs instead of HIGH | |
digitalWrite(ledPinRed, HIGH); //HIGH turns of LEDs | |
digitalWrite(ledPinYellow, HIGH); | |
Serial.println(value); | |
} else if ( (value > 315) && ( value <= 335) ) { | |
digitalWrite(ledPinYellow, LOW); | |
digitalWrite(ledPinGreen, HIGH); | |
digitalWrite(ledPinRed, HIGH); | |
Serial.println(value); | |
} else if (value > 335) { | |
digitalWrite(ledPinRed, LOW); | |
digitalWrite(ledPinGreen, HIGH); | |
digitalWrite(ledPinYellow, HIGH); | |
Serial.println(value); | |
} | |
// pause for .3 seconds | |
delay(300); //This makes the transistions between LEDs smooth | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment