KelvinMead

WS2811 / Fast_SPI2 / Bouncing Ball

Aug 24th, 2013
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. /* bouncing ball
  2. /* Kelvin Mead Aug/14
  3. /* WS2811 / Fast_SPI2
  4. */
  5.  
  6. #include <FastSPI_LED2.h>
  7.  
  8. #define NUM_LEDS 320
  9.  
  10. CRGB leds[NUM_LEDS];
  11.  
  12. long previousMillis = 0; // will store last time LED was updated
  13. long interval = 100; // interval at which to blink (milliseconds)
  14. int bright = 255; // easy adjustable brightness
  15. const int ledsperstrip = 32;
  16.  
  17. // for edge definition
  18. int x = 0;
  19. int y = 0;
  20. int rowcount = 10;
  21. int xdirection = 0;
  22. int ydirection = 0;
  23. int boxx = 10;
  24. int boxy = 32;
  25.  
  26. void setup() {
  27. delay(2000);
  28. LEDS.setBrightness(bright);
  29. LEDS.addLeds<WS2811, 13>(leds, NUM_LEDS);
  30. }
  31.  
  32. void loop() {
  33.  
  34. unsigned long currentMillis = millis();
  35. if(currentMillis - previousMillis > interval) {
  36. previousMillis = currentMillis;
  37.  
  38. //put programs in here to be controlled by the delay time
  39. // program name (r, g, b, speed)
  40. bouncingball();
  41.  
  42. LEDS.setBrightness(bright);
  43. } // end timed loop
  44. } // end void loop
  45.  
  46. void bouncingball() {
  47. if(xdirection == 0) {
  48. boxx++;
  49. if (boxx == 6) {
  50. xdirection = 1;
  51. boxx--;
  52. }
  53. }
  54. if(xdirection == 1) {
  55. boxx--;
  56. if (boxx == 0) {
  57. xdirection = 0;
  58. }
  59. }
  60. if(ydirection == 0) {
  61. boxy++;
  62. if (boxy == 4) {
  63. ydirection = 1;
  64. boxy--;
  65. }
  66. }
  67. if(ydirection == 1) {
  68. boxy--;
  69. if (boxy == 0) {
  70. ydirection = 0;
  71. }
  72. }
  73.  
  74. if(boxy%2 == 1) { // row is odd
  75. leds[(boxy * rowcount) + ((rowcount-1)-boxx)].setRGB(255,255,255);
  76. } else { // row is even
  77. leds[(boxy*rowcount) + boxx].setRGB(255,255,255);
  78. }
  79.  
  80. FastSPI_LED.show();
  81. }
Advertisement
Add Comment
Please, Sign In to add comment