Created
December 26, 2011 18:04
-
-
Save bemurphy/1521780 to your computer and use it in GitHub Desktop.
red green blue for tri color led and tdd
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
| const int RED_LED_PIN = 9; | |
| const int GREEN_LED_PIN = 10; | |
| const int BLUE_LED_PIN = 11; | |
| String inputString = ""; | |
| boolean stringComplete = false; | |
| void setup() { | |
| Serial.begin(9600); | |
| inputString.reserve(100); | |
| } | |
| void loop(){ | |
| if (stringComplete) { | |
| Serial.println(inputString); | |
| if (inputString == "failed") { | |
| setColor(RED_LED_PIN); | |
| } else if (inputString == "pending") { | |
| setColor(BLUE_LED_PIN); | |
| } else { | |
| setColor(GREEN_LED_PIN); | |
| } | |
| inputString = ""; | |
| stringComplete = false; | |
| } | |
| } | |
| void resetLED() { | |
| analogWrite(RED_LED_PIN, 0); | |
| analogWrite(GREEN_LED_PIN, 0); | |
| analogWrite(BLUE_LED_PIN, 0); | |
| } | |
| void setColor(int pin) { | |
| resetLED(); | |
| analogWrite(pin, 128); | |
| } | |
| void serialEvent() { | |
| while (Serial.available()) { | |
| char inChar = (char)Serial.read(); | |
| if (inChar == '\n') { | |
| stringComplete = true; | |
| } else { | |
| inputString += inChar; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment