daily pastebin goal
52%
SHARE
TWEET

ARDUINO MOOD LAMP PROGRAM MAKUSEOF

a guest Jul 22nd, 2014 3,211 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  Mood Lamp - oscillates between colors
  3.  */
  4.  
  5. // each pin corresponds to an LED color:
  6. int led0 = 10;
  7. int led1 = 11;
  8. int led2 = 12;
  9.  
  10. //declare internal variables
  11. int brightness = 200;
  12. int red = 0;
  13. int blue = 0;
  14. int green = 0;
  15.  
  16. // this routine runs each time you hit the reset button
  17. void setup() {                
  18.   // declare the relevant pins to be output
  19.   pinMode(led0, OUTPUT);    
  20.   pinMode(led1, OUTPUT);    
  21.   pinMode(led2, OUTPUT);    
  22. }
  23.  
  24. // this routine loops indefinitely
  25. void loop() {
  26.     for (float x=0;x < PI; x = x + 0.000004){
  27.       red = brightness * abs(sin(x*(180/PI)));           // calculate red brightness
  28.       green = brightness * abs(sin((x+PI/3)*(180/PI)));    // calculate green brightness
  29.       blue = brightness * abs(sin((x+(2*PI)/3)*(180/PI)));// calculate the blue brightness
  30.       analogWrite(led0, red);   // send the value to the LED
  31.       analogWrite(led1, green);   // send the value to the LED
  32.       analogWrite(led2, blue);   // send the value to the LED
  33.     }
  34.  
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top