Skip to content

Instantly share code, notes, and snippets.

@takano32
Created May 19, 2009 12:37
Show Gist options
  • Save takano32/114070 to your computer and use it in GitHub Desktop.
Save takano32/114070 to your computer and use it in GitHub Desktop.
#define R 5
#define G 6
#define B 7
#define S 2
#define WAIT 500
int inByte = 0;
int inSwitch;
bool r, g, b, blink, off;
void setup() {
Serial.begin(9600);
r = g = b = blink = off = false;
pinMode(S, INPUT);
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
}
void loop() {
int wait = WAIT;
if (Serial.available() > 0) {
inByte = Serial.read();
Serial.println(inByte);
// blink = inByte & 0x10 ? true : false;
//0x20
off = inByte & 0x80 ? true : false;
r = inByte & 0x01 ? (!off ? true : false) : r;
g = inByte & 0x02 ? (!off ? true : false) : g;
b = inByte & 0x04 ? (!off ? true : false) : b;
}
inSwitch = digitalRead(S);
if (inSwitch == HIGH) {
// r = g = b = LOW;
wait = WAIT;
Serial.write(0);
} else {
// r = g = b = HIGH;
wait = WAIT / 2;
Serial.write(1);
}
digitalWrite(R, r ? HIGH : LOW);
digitalWrite(G, g ? HIGH : LOW);
digitalWrite(B, b ? HIGH : LOW);
delay(wait);
digitalWrite(R, LOW);
digitalWrite(G, LOW);
digitalWrite(B, LOW);
delay(wait);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment