Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 4th, 2013  |  syntax: None  |  size: 0.61 KB  |  views: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. int y,counter,redVal,greenVal,blueVal;
  2. int RGB[2];
  3.  
  4. void setup() {
  5.   randomSeed(analogRead(A1));
  6.   Serial.begin(9600);
  7. }
  8.  
  9. void loop() {
  10. // y = random(765);
  11. for(int x=255;x>=0;x--){
  12. analogWrite(9, getColor(RGB[0]));
  13. analogWrite(10, getColor(RGB[1]));
  14. analogWrite(11, getColor(RGB[2]));
  15. counter = x * 3;
  16. RGB[0] = counter;
  17. RGB[2] = (counter + 255) % 765;
  18. RGB[1] = (RGB[2] + 255) % 765;
  19. delay(10);
  20. }
  21. }
  22. int getColor(int x){
  23.   int phase = x / 255;
  24.   int mod = x % 255;
  25.   if (phase == 0){
  26.     return 0;
  27.   }
  28.   if(phase == 1){
  29.     return mod;
  30.   }
  31.   if(phase == 2){
  32.     return 255 - mod;
  33.   }
  34. }
clone this paste RAW Paste Data