Created
February 9, 2014 00:50
-
-
Save Jasmien/8892602 to your computer and use it in GitHub Desktop.
If you turn the potentiometer up, more LEDs light up and vice versa.
This file contains hidden or 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
// assign names and values | |
int green1 = 2; | |
int green2 = 3; | |
int green3 = 4; | |
int yellow1 = 5; | |
int yellow2 = 6; | |
int yellow3 = 7; | |
int red1 = 8; | |
int red2 = 9; | |
int red3 = 10; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
// initialize serial communication at 9600 bits per second: | |
Serial.begin(9600); | |
// initialize the digital pin as an output. | |
pinMode(green1, OUTPUT); | |
pinMode(green2, OUTPUT); | |
pinMode(green3, OUTPUT); | |
pinMode(yellow1, OUTPUT); | |
pinMode(yellow2, OUTPUT); | |
pinMode(yellow3, OUTPUT); | |
pinMode(red1, OUTPUT); | |
pinMode(red2, OUTPUT); | |
pinMode(red3, OUTPUT); | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
// read the input on analog pin 0: | |
int sensorValue = analogRead(A0); | |
// print out the value you read: | |
Serial.println(sensorValue); | |
// number of leds according to signal strength (0 - 1024) | |
if (sensorValue > 102) // 1 | |
digitalWrite(green1, HIGH); | |
if (sensorValue > 204) // 2 | |
digitalWrite(green2, HIGH); | |
if (sensorValue > 306) // 3 | |
digitalWrite(green3, HIGH); | |
if (sensorValue > 408) // 4 | |
digitalWrite(yellow1, HIGH); | |
if (sensorValue > 510) // 5 | |
digitalWrite(yellow2, HIGH); | |
if (sensorValue > 612) // 6 | |
digitalWrite(yellow3, HIGH); | |
if (sensorValue > 714) // 7 | |
digitalWrite(red1, HIGH); | |
if (sensorValue > 816) // 8 | |
digitalWrite(red2, HIGH); | |
if (sensorValue > 918) // 9 | |
digitalWrite(red3, HIGH); | |
delay(1); // delay in between reads for stability | |
for (int i = 2; i < 11; i++) | |
digitalWrite(i, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment