Skip to content

Instantly share code, notes, and snippets.

@winhamwr
Created August 23, 2010 21:50
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 winhamwr/546417 to your computer and use it in GitHub Desktop.
Save winhamwr/546417 to your computer and use it in GitHub Desktop.
const int ledGreenPin = 3;
const int ledBluePin = 4;
int incomingByte;
void setup() {
// initialize serial communication:
Serial.begin(9600);
Serial.print("YOYOYO\n");
// initialize the LED pin as an output:
pinMode(ledRedPin, OUTPUT);
pinMode(ledGreenPin, OUTPUT);
pinMode(ledBluePin, OUTPUT);
}
void redOn() {
digitalWrite(ledRedPin, HIGH);
digitalWrite(ledGreenPin, LOW);
digitalWrite(ledBluePin, LOW);
}
void greenOn() {
digitalWrite(ledRedPin, LOW);
digitalWrite(ledGreenPin, HIGH);
digitalWrite(ledBluePin, LOW);
}
void blueOn() {
digitalWrite(ledRedPin, LOW);
digitalWrite(ledGreenPin, LOW);
digitalWrite(ledBluePin, HIGH);
}
void testResponse() {
Serial.print("SUCCESS\n");
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
if (incomingByte == 'R') {
redOn();
}
if (incomingByte == 'G') {
greenOn();
}
if (incomingByte == 'B') {
blueOn();
}
if (incomingByte == 'T') {
digitalWrite(ledRedPin, HIGH);
digitalWrite(ledGreenPin, HIGH);
digitalWrite(ledBluePin, HIGH);
testResponse();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment