Created
June 29, 2016 19:15
-
-
Save GreenMoonArt/24987b91369846162ed823c56d358363 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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