Skip to content

Instantly share code, notes, and snippets.

@GreenMoonArt
Created June 29, 2016 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GreenMoonArt/24987b91369846162ed823c56d358363 to your computer and use it in GitHub Desktop.
Save GreenMoonArt/24987b91369846162ed823c56d358363 to your computer and use it in GitHub Desktop.
/* This is a simple way to use one potentiometer to get varying colors out of a common-cathode RGB LED
Check out this sketch to cycle through millions of colors: https://gist.github.com/jamesotron/766994
*/
int sensorPin = A0; // connect a sensor or potentiometer to analog input A0
int sensorValue = 0;
int redPin = 3; // use PWM outputs on digital pins 3, 5, 6 - connect to RGB LED via 220 Ohm resistors
int greenPin = 5;
int bluePin = 6;
void setup()
{ /* nothing to do in setup */ }
void loop()
{
sensorValue = analogRead(sensorPin);
analogWrite(redPin, sensorValue);
analogWrite(greenPin, sensorValue/2); // dividing by different numbers to get some color variability
analogWrite(bluePin, sensorValue/3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment