Last active
January 4, 2016 01:49
-
-
Save kirberich/8550926 to your computer and use it in GitHub Desktop.
Arduino RGB LED strip test sketch
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
| // Red on 5, green on 6, blue on 9 | |
| byte rgb_pins[ ] = {5, 6, 9}; | |
| byte white_calibration[ ] = {255, 128, 64}; | |
| void set_color(float rp, float gp, float bp) { | |
| analogWrite(rgb_pins[0], floor(rp*white_calibration[0])); | |
| analogWrite(rgb_pins[1], floor(gp*white_calibration[1])); | |
| analogWrite(rgb_pins[2], floor(bp*white_calibration[2])); | |
| } | |
| void setup() { | |
| // Change timer 1 to fast PWM | |
| // AKA the magic no-flicker-button | |
| bitSet(TCCR1B, WGM12); | |
| pinMode(rgb_pins[0], OUTPUT); | |
| pinMode(rgb_pins[1], OUTPUT); | |
| pinMode(rgb_pins[2], OUTPUT); | |
| set_color(1, 1, 1); | |
| delay(1000); | |
| } | |
| void loop() { | |
| set_color(random(100)/100.0, random(100)/100.0, random(100)/100.0); | |
| //set_color(0.2, 0.5, 0.5); | |
| delay(3000); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment