Advertisement
Guest User

Untitled

a guest
Jan 4th, 2013
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement