Created
June 9, 2015 05:47
-
-
Save jimwhitfield/f93ed35c692e9aac886c to your computer and use it in GitHub Desktop.
RGB_dial
This file contains hidden or 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
// Gray text with two slashes are just helpful comments, you don’t need to type them. :) | |
/******* -----=====!! EASY STUFF TO MESS WITH !!=====------ ******/ | |
// What analog pin should we use to read the value from the potentiometer? | |
int analogPin = 2; // Yep, you heard right: The coolest of the Analog pins... | |
// What pins are the LEDs connected to? | |
int redPin = 9; | |
int greenPin = 10; | |
int bluePin = 11; | |
int whitePin = 6; | |
/******* -----=====^^ EASY STUFF TO MESS WITH ^^=====------ ******/ | |
void setup() { | |
pinMode(redPin, OUTPUT); // Setup ledPin as an output. | |
pinMode(greenPin, OUTPUT); // Setup ledPin as an output. | |
pinMode(bluePin, OUTPUT); // Setup ledPin as an output. | |
pinMode(dimmerPin, OUTPUT); | |
} | |
void loop() { | |
int analogValue = map(analogRead(analogPin), 0, 1023, 0, 255); | |
int r, g, b; | |
analogWrite(dimmerPin, analogValue); | |
if (analogValue < 85) { | |
r = 255 - analogValue * 3; | |
g = 0; | |
b = analogValue * 3; | |
} else if (analogValue < 170) { | |
analogValue -= 85; | |
r = 0; | |
g = analogValue * 3; | |
b = 255 - analogValue * 3; | |
} else { | |
analogValue -= 170; | |
r = analogValue * 3; | |
g = 255 - analogValue * 3; | |
b = 0; | |
} | |
analogWrite(redPin, r); | |
analogWrite(greenPin, g); | |
analogWrite(bluePin, b); | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment