Advertisement
obernardovieira

[Arduino] A walk through the spectrum (RGB LED)

Aug 21st, 2015
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.32 KB | None | 0 0
  1. //here is the example using Fritzing
  2. //http://1drv.ms/1h1cQKQ
  3. //(the link is to OneDrive)
  4. //in this case I'm using a RGB Anode led
  5. //and, for those who does not know hoe the RGB led works, here's the answer
  6. //http://www.instructables.com/answers/How-do-multi-colored-led-lights-work/
  7.  
  8.  
  9. // Init the Pins used for PWM
  10. const int redPin = 9;
  11. const int greenPin = 10;
  12. const int bluePin = 11;
  13.  
  14. const int buttonPin = 13;
  15. int buttonState = LOW;
  16.  
  17. int currentColorValueRed;
  18. int currentColorValueGreen;
  19. int currentColorValueBlue;
  20.  
  21. void setup()
  22. {
  23.   pinMode(redPin, OUTPUT);
  24.   pinMode(greenPin, OUTPUT);
  25.   pinMode(bluePin, OUTPUT);
  26.  
  27.   pinMode(buttonPin, INPUT);
  28.   Serial.begin(9600);
  29. }
  30.  
  31. void loop()
  32. {
  33.  
  34.   int i;
  35.  
  36.   currentColorValueRed = 0;
  37.   currentColorValueGreen = 255;
  38.   currentColorValueBlue = 255;
  39.  
  40.   analogWrite(redPin, currentColorValueRed);
  41.   analogWrite(greenPin, currentColorValueGreen);
  42.   analogWrite(bluePin, currentColorValueBlue);
  43.  
  44.   for(i = 255; i > 0; i--) {
  45.     currentColorValueGreen --;
  46.     analogWrite(redPin, currentColorValueRed);
  47.     analogWrite(greenPin, currentColorValueGreen);
  48.     analogWrite(bluePin, currentColorValueBlue);
  49.     delay(10);
  50.   }
  51.   for(i = 255; i > 0; i--) {
  52.     currentColorValueRed ++;
  53.     analogWrite(redPin, currentColorValueRed);
  54.     analogWrite(greenPin, currentColorValueGreen);
  55.     analogWrite(bluePin, currentColorValueBlue);
  56.     delay(10);
  57.   }
  58.   for(i = 255; i > 0; i--) {
  59.     currentColorValueBlue --;
  60.     analogWrite(redPin, currentColorValueRed);
  61.     analogWrite(greenPin, currentColorValueGreen);
  62.     analogWrite(bluePin, currentColorValueBlue);
  63.     delay(10);
  64.   }
  65.   for(i = 255; i > 0; i--) {
  66.     currentColorValueGreen ++;
  67.     analogWrite(redPin, currentColorValueRed);
  68.     analogWrite(greenPin, currentColorValueGreen);
  69.     analogWrite(bluePin, currentColorValueBlue);
  70.     delay(10);
  71.   }
  72.   for(i = 255; i > 0; i--) {
  73.     currentColorValueRed --;
  74.     analogWrite(redPin, currentColorValueRed);
  75.     analogWrite(greenPin, currentColorValueGreen);
  76.     analogWrite(bluePin, currentColorValueBlue);
  77.     delay(10);
  78.   }
  79.   for(i = 255; i > 0; i--) {
  80.     currentColorValueBlue ++;
  81.     analogWrite(redPin, currentColorValueRed);
  82.     analogWrite(greenPin, currentColorValueGreen);
  83.     analogWrite(bluePin, currentColorValueBlue);
  84.     delay(10);
  85.   }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement