Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* bouncing ball
- /* Kelvin Mead Aug/14
- /* WS2811 / Fast_SPI2
- */
- #include <FastSPI_LED2.h>
- #define NUM_LEDS 320
- CRGB leds[NUM_LEDS];
- long previousMillis = 0; // will store last time LED was updated
- long interval = 100; // interval at which to blink (milliseconds)
- int bright = 255; // easy adjustable brightness
- const int ledsperstrip = 32;
- // for edge definition
- int x = 0;
- int y = 0;
- int rowcount = 10;
- int xdirection = 0;
- int ydirection = 0;
- int boxx = 10;
- int boxy = 32;
- void setup() {
- delay(2000);
- LEDS.setBrightness(bright);
- LEDS.addLeds<WS2811, 13>(leds, NUM_LEDS);
- }
- void loop() {
- unsigned long currentMillis = millis();
- if(currentMillis - previousMillis > interval) {
- previousMillis = currentMillis;
- //put programs in here to be controlled by the delay time
- // program name (r, g, b, speed)
- bouncingball();
- LEDS.setBrightness(bright);
- } // end timed loop
- } // end void loop
- void bouncingball() {
- if(xdirection == 0) {
- boxx++;
- if (boxx == 6) {
- xdirection = 1;
- boxx--;
- }
- }
- if(xdirection == 1) {
- boxx--;
- if (boxx == 0) {
- xdirection = 0;
- }
- }
- if(ydirection == 0) {
- boxy++;
- if (boxy == 4) {
- ydirection = 1;
- boxy--;
- }
- }
- if(ydirection == 1) {
- boxy--;
- if (boxy == 0) {
- ydirection = 0;
- }
- }
- if(boxy%2 == 1) { // row is odd
- leds[(boxy * rowcount) + ((rowcount-1)-boxx)].setRGB(255,255,255);
- } else { // row is even
- leds[(boxy*rowcount) + boxx].setRGB(255,255,255);
- }
- FastSPI_LED.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment