/*
Sample program to control the color of a RGB LED via the keyboard
Set the correct PWM pins that are connected to the RGB LED
*/
#define redPin 7
#define greenPin 6
#define bluePin 5
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
Serial.begin(9600);
}
void loop() {
while (Serial.available() == 0); // wait until a value is entered
Serial.println("Enter Red value [0-255]:");
int red = Serial.parseInt(); // get the PWM value for red led
delay(100);
while (Serial.available() == 0); // wait until a value is entered
Serial.println("Enter Green value [0-255]:");
int green = Serial.parseInt(); // get the PWM value for green led
delay(100);
while (Serial.available() == 0); // wait until a value is entered
Serial.println("Enter Blue value [0-255]:");
int blue = Serial.parseInt(); // get the PWM value for blue led
delay(100);
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
Comments