Skip to content

Instantly share code, notes, and snippets.

@octaflop
Created May 21, 2014 02:57
Show Gist options
  • Select an option

  • Save octaflop/78c8c60d2cca05f404c4 to your computer and use it in GitHub Desktop.

Select an option

Save octaflop/78c8c60d2cca05f404c4 to your computer and use it in GitHub Desktop.
light show!
/*
Arduino colour mood setter
*/
int const rled = 11;
int const gled = 10;
int const bled = 9;
int const rrgb = 7;
int const grgb = 5;
int const brgb = 6;
int const potPin = A0;
int potVal;
int delta;
int rfactor, gfactor, bfactor;
int transition = 10;
void setup() {
Serial.begin(9600);
}
void loop() {
potVal = analogRead(potPin);
Serial.println("Pot val:");
Serial.println(potVal);
// Calculate factors
int delta = map(potVal, 0, 1023, 0, 255);
rfactor = (delta);
gfactor = (delta - 43);
bfactor = (delta - 85);
Serial.println("factors");
Serial.println(rfactor);
Serial.println(gfactor);
Serial.println(bfactor);
// Red LEDs
//analogWrite(rled, rfactor);
// Green LEDs
//analogWrite(gled, gfactor);
// Blue LEDs
//analogWrite(bled, bfactor);
if (rfactor >= 0) {
analogWrite(rled, 255);
analogWrite(rrgb, 255);
} else {
digitalWrite(rled, LOW);
digitalWrite(rrgb, LOW);
}
if (gfactor >= 0) {
analogWrite(gled, 255);
analogWrite(grgb, 255);
} else {
digitalWrite(gled, LOW);
digitalWrite(grgb, LOW);
}
if (bfactor >= 0) {
analogWrite(bled, 255);
analogWrite(brgb, 255);
} else {
digitalWrite(bled, LOW);
digitalWrite(brgb, LOW);
}
delay(transition);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment