colordial.ino
/****************************************
* *
* colordial.ino *
* Eric Ayars *
* 4/4/12 *
* *
* Reads three pots, sets RGB color *
* accordingly. Also reports RGB *
* tuples on the serial line. *
* *
****************************************/
byte Red = 3; // Red PWM pin
byte Green = 5; // Green PWM pin
byte Blue = 6; // Blue PWM pin
byte Ri = 0; // input pins for RGB
byte Gi = 1;
byte Bi = 2;
void setup() {
Serial.begin(9600);
pinMode(Red, OUTPUT);
pinMode(Green, OUTPUT);
pinMode(Blue, OUTPUT);
}
void setColor(byte r,byte g,byte b) {
r = 255-r;
g = 255-g;
b = 255-b;
analogWrite(Red, r);
analogWrite(Green, g);
analogWrite(Blue, b);
}
void loop()
{
byte R = map(analogRead(Ri), 0, 1023, 0, 255);
byte G = map(analogRead(Gi), 0, 1023, 0, 255);
byte B = map(analogRead(Bi), 0, 1023, 0, 255);
setColor(R,G,B);
Serial.print(R, DEC);
Serial.print(' ');
Serial.print(G, DEC);
Serial.print(' ');
Serial.print(B, DEC);
Serial.print('\n');
delay(200);
}
Generated by GNU enscript 1.6.4.