Skip to content

Instantly share code, notes, and snippets.

@takano32
Created July 14, 2009 16:25
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 takano32/147039 to your computer and use it in GitHub Desktop.
Save takano32/147039 to your computer and use it in GitHub Desktop.
Ruby on Arduino
#define R 2
#define G 3
#define B 4
#define S 5
#define WAIT 500
int inByte = 0;
int inSwitch = HIGH;
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