Strip a trailing space
[JMPrope_player.git] / JMPRope_player.ino
1 #include <FastLED.h>
2 #include <FastLED_animation.h>
3
4 #include "BareButton.h"
5
6 //#include "animations/Adafruit.h"
7 //#include "animations/Debian.h"
8 //#include "animations/Firefox.h"
9 #include "animations/JMPrope.h"
10 //#include "animations/Openhardware.h"
11 //#include "animations/Opensource.h"
12 //#include "animations/S.S.C.Napoli.h"
13 //#include "animations/ao2.h"
14 //#include "animations/ao2it.h"
15
16 #define DATA_PIN 0
17 #define INPUT_PIN 2
18
19 /* This is the same exposure time to set up on the camera */
20 #define EXPOSURE_TIME_MSEC 500UL
21
22 static struct CRGB leds[NUM_LEDS];
23
24 static BareButton button = BareButton(INPUT_PIN);
25 static unsigned long frame_delay_usecs = EXPOSURE_TIME_MSEC * 1000UL / NUM_FRAMES;
26
27 void setup()
28 {
29         LEDS.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
30 }
31
32 void loop()
33 {
34         unsigned long remaining;
35         unsigned long elapsed = 0;
36
37         if (button.isPressed()) {
38                 unsigned long t0 = micros();
39                 animation.draw(leds);
40                 elapsed = micros() - t0;
41         } else {
42                 for (int i = 0; i < NUM_LEDS; i++)
43                         leds[i] = CRGB(0, 0, 0);
44                 LEDS.show();
45                 animation.reset();
46         }
47         remaining = frame_delay_usecs - elapsed;
48 #if 0
49         /* use leds to show how many _milliseconds_ we will have to wait to
50          * achieve a constant framerate */
51         for (unsigned int i = 0; i < NUM_LEDS; i++)
52                 leds[i] = CRGB(0, 0, 0);
53         for (unsigned int i = 0; i < remaining / 1000; i++)
54                 leds[i] = CRGB(255, 0, 0);
55         LEDS.show();
56         delay(100);
57 #else
58         delayMicroseconds(remaining);
59 #endif
60 }