Skip to content

Instantly share code, notes, and snippets.

@kobeBigs
Created May 24, 2013 15:09
Show Gist options
  • Save kobeBigs/bb12ebcfd518720c2b25 to your computer and use it in GitHub Desktop.
Save kobeBigs/bb12ebcfd518720c2b25 to your computer and use it in GitHub Desktop.
Serial Interface & RGB LED a simple sketch to randomly change colors of RGB LED and write out Serial output.
/**
* a simple sketch to randomly change colors of RGB LED
* and write out Serial output.
*/
int redPin = 11;
int bluePin = 10;
int greenPin = 9;
//setup
void setup(){
Serial.begin(9600);
}
//loop
void loop(){
int valRedPin = random(0, 256);
int valBluePin = random (0, 256);
int valGreenPin = random (0, 256);
//write to RGB LED
analogWrite(redPin, valRedPin);
analogWrite(greenPin, valGreenPin);
analogWrite(bluePin, valBluePin);
//send Serial output to PC
Serial.print(analogRead(redPin));
Serial.print(",");
Serial.print(analogRead(greenPin));
Serial.print(",");
Serial.println(analogRead(bluePin));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment