Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Arduino for kids - Mood Light
- *
- * learnelectronics
- * 4 JUL 2017
- *
- * www.youtube.com/c/learnelectronics
- *
- * Common Cathode RGB LED
- *
- * [ ]
- * [ ]
- * -----
- * ||||
- * RGGB
- * ERRL
- * DOEU
- * UEE
- * N
- * D
- *
- */
- #define led0 9 //RED LED on PWM pin 9
- #define led1 10 //GREEN LED on PWM pin 9
- #define led2 12 //BLUE LED on PWM pin 9
- int brightness = 200; //Set brightnes refererence
- int red = 0; //Set RED to 0
- int blue = 0; //Set Blue to 0
- int green = 0; //Set Green to 0
- void setup() {
- pinMode(led0,OUTPUT); //sets pin 9 to output
- pinMode(led1,OUTPUT); //sets pin 10 to output
- pinMode(led2,OUTPUT); //sets pin 11 to output
- }
- void loop() {
- for (float x= 0;x <PI; x = x + 0.000004){
- red = brightness * abs(sin(x*(180/PI))); //do some trig to calculate a value for red
- green = brightness * abs(sin((x+PI/3)*(180/PI))); //do some trig to calculate a value for green
- blue = brightness * abs(sin((x+2*PI)/3)*(180/PI)); //do some trig to calculate a value for blue
- analogWrite(led0, red); //send the value for red to red LED
- analogWrite(led1, green); //send the value for green to green LED
- analogWrite(led2, blue); //send the value for blue to blue LED
- } //end of for loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement