Skip to content

Instantly share code, notes, and snippets.

@nathans
Created February 15, 2011 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathans/827245 to your computer and use it in GitHub Desktop.
Save nathans/827245 to your computer and use it in GitHub Desktop.
Controls the color of a tri-color LED based on analog input
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