Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
int redLed = 3;
int greenLed = 5;
int blueLed = 6;
int whiteLed = 9;
void setup() {
Serial.begin(9600); // initialize serial communications
Serial.setTimeout(10); // set the timeout for parseInt
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(whiteLed, OUTPUT);
}
void loop() {
if (Serial.available() > 0) { // if there's serial data available
int red = Serial.parseInt();
int newRed = map(red, 255, 0, 0, 255);
int green = Serial.parseInt();
int newGreen = map(green, 255, 0, 0, 255);
int blue = Serial.parseInt();
int newBlue = map(blue, 255, 0, 0, 255);
int white = Serial.parseInt();
int newWhite = map(white, 255, 0, 0, 255);
if (Serial.read() == '\n') {
analogWrite(redLed, newRed);
analogWrite(greenLed, newGreen);
analogWrite(blueLed, newBlue);
analogWrite(whiteLed, newWhite);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.