Created
February 15, 2011 07:53
-
-
Save nathans/827245 to your computer and use it in GitHub Desktop.
Controls the color of a tri-color LED based on analog input
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
int redPin = 9; | |
int greenPin = 10; | |
int bluePin = 11; | |
int analogPin = 3; | |
int val = 0; | |
void setup() | |
{ | |
pinMode(redPin, OUTPUT); // sets the pin as output | |
pinMode(greenPin, OUTPUT); | |
pinMode(bluePin, OUTPUT); | |
} | |
void loop() | |
{ | |
val = analogRead(analogPin); // read the input pin | |
if (val <= 341) { | |
digitalWrite(redPin, HIGH); | |
digitalWrite(greenPin, LOW); | |
digitalWrite(bluePin, LOW); | |
} | |
else if (val >= 683) { | |
digitalWrite(redPin, LOW); | |
digitalWrite(greenPin, LOW); | |
digitalWrite(bluePin, HIGH); | |
} | |
else { | |
digitalWrite(redPin, LOW); | |
digitalWrite(greenPin, HIGH); | |
digitalWrite(bluePin, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment