Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- FastLED Animations
- This uses a Neopixel strip, with optionally CRGBSet for multiple effects on one pin/strip.
- NOTE: The below assumes you can already set up a Neopixel strip using FastLED on an Arduino, without Bottango.
- To control a FastLED animation, in Bottango, create an On/Off event:
- Build > Custom Events > On/Off
- Give it a name ("Cylon" in this example)
- Select Live On Project Launch
- Set Identifier, and use the Identifier in the Arduino code in BottangoArduinoCallbacks.cpp:
- - Define boolean at top
- - onLateLoop (react to the state of the boolean)
- - onOnOffCustomEventOnOffChanged (set state of boolean on/off, this follows Bottango UI command)
- No need to set the Hardware pin.
- Summary - Updates to Bottango Arduino driver
- --------------------------------------------
- Four changes needed from a standard FastLED Arduino sketch:
- A. Includes and defines go to top of BottangoArduinoCallbacks.cpp, after Bottango includes/defines
- 1. This includes setting up a boolean to control the animation on/off state
- B. Setup code goes to onThisControllerStarted
- C. Main loop code goes to onLateLoop()
- 1. On/Off conditions are handled in two if statements
- D. Boolean is checked in onOnOffCustomEventOnOffChanged
- For more than one animation on a single Neopixel strip:
- A. Use CRGBSet
- CRGBArray<NUM_LEDS> leds; // at top with includes/defines, replaces regular version: CRGB leds[NUM_LEDS];
- B. Include animation code in onLateLoop()
- Two if statements to turn effect on and off
- C. Add boolean to onOffCustomEventOnOffChanged
- Example:
- if (strcmp(effectorIdentifier, "Eyes") == 0) {
- Eyes_on = !Eyes_on;
- }
- D. Setup code in onThisControllerStarted covers the entire strip, even if using CRGBSet.
- */
- // Details:
- // Add this code to BottangoArduinoCallbacks.cpp
- // At top below other Includes, set up FastLED:
- // FastLED setup:
- #include "FastLED.h"
- #define DATA_PIN 14
- #define LED_TYPE NEOPIXEL
- #define COLOR_ORDER GRB
- #define NUM_LEDS 8
- #define BRIGHTNESS 75
- CRGB leds[NUM_LEDS];
- // Or this if using long string of Neopixels and addressing part of them with CRGBSet:
- CRGBArray<NUM_LEDS> leds;
- bool Cylon_animating = false; // Controls FastLED effect on/off
- // Initialize FastLED when controller boots up
- void onThisControllerStarted() {
- FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- }
- // Animation code
- // To control the animation, the main code from a regular FastLED loop() is moved to onLateLoop()
- // Bottango looks for bool (such as Cylon_animating) to be set to True and if Yes, then runs the animation.
- // Note - handle both on and off conditions.
- void onLateLoop() {
- if (Cylon_animating == true) {
- FastLED.setBrightness(BRIGHTNESS); // 0 - 255, 8-bit
- uint16_t i = beatsin16(25, 0, NUM_LEDS - 1); // 25 in this is how many beats per minute
- leds[i] = CRGB::Blue;
- FastLED.show();
- fadeToBlackBy(leds, NUM_LEDS, 8);
- }
- // If bool is False, then turn off all Neopixels
- if (Cylon_animating == false) {
- for (int i = 0; i < NUM_LEDS; ++i) { // All off
- leds[i] = CRGB::Black;
- FastLED.show();
- }
- }
- }
- // Turn on or off the FastLED animation state
- // This is controlled by the On/Off event in the Bottango UI
- void onOnOffCustomEventOnOffChanged(AbstractEffector *effector, bool on) {
- char effectorIdentifier[9];
- effector->getIdentifier(effectorIdentifier, 9);
- if (strcmp(effectorIdentifier, "Cylon") == 0) { // Edit the Identifier ("Cylon") to match On/Off event
- Cylon_animating = !Cylon_animating;
- }
- }
- // Changing the color of FastLED pixels
- // Details of onColorCustomEventColorChanged
- // Initialization is in onThisControllerStarted
- // No need for boolean or any code in onLateLoop, it's handled in onColorCustomEventColorChanged
- void onColorCustomEventColorChanged(AbstractEffector* effector, byte newRed, byte newGreen, byte newBlue) {
- // example, set rgb LED on pins 3, 5, and 6 to given red, green, and blue colors (represented as a byte between 0 and 255)
- char effectorIdentifier[9];
- effector->getIdentifier(effectorIdentifier, 9);
- if (strcmp(effectorIdentifier, "eyeColor") == 0) {
- CRGBSet firstTwo(leds(0, 1)); // Addresses the first two pixels of the strand
- fill_solid(firstTwo, 2, CRGB(newRed, newGreen, newBlue)); // The "2" is just the first two, for the eyes
- FastLED.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement