Advertisement
BurningWreck

Bottango - FastLED setup

Apr 23rd, 2025 (edited)
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.38 KB | Software | 0 0
  1. /*
  2. FastLED Animations
  3.  
  4. This uses a Neopixel strip, with optionally CRGBSet for multiple effects on one pin/strip.
  5. NOTE: The below assumes you can already set up a Neopixel strip using FastLED on an Arduino, without Bottango.
  6.  
  7. To control a FastLED animation, in Bottango, create an On/Off event:
  8.  
  9. Build > Custom Events > On/Off
  10. Give it a name ("Cylon" in this example)
  11. Select Live On Project Launch
  12. Set Identifier, and use the Identifier in the Arduino code in BottangoArduinoCallbacks.cpp:
  13. - Define boolean at top
  14. - onLateLoop (react to the state of the boolean)
  15. - onOnOffCustomEventOnOffChanged (set state of boolean on/off, this follows Bottango UI command)
  16.  
  17. No need to set the Hardware pin.
  18.  
  19. Summary - Updates to Bottango Arduino driver
  20. --------------------------------------------
  21. Four changes needed from a standard FastLED Arduino sketch:
  22. A. Includes and defines go to top of BottangoArduinoCallbacks.cpp, after Bottango includes/defines
  23.         1. This includes setting up a boolean to control the animation on/off state
  24. B. Setup code goes to onThisControllerStarted
  25. C. Main loop code goes to onLateLoop()
  26.         1. On/Off conditions are handled in two if statements
  27. D. Boolean is checked in onOnOffCustomEventOnOffChanged
  28.  
  29. For more than one animation on a single Neopixel strip:
  30. A. Use CRGBSet
  31.     CRGBArray<NUM_LEDS> leds;  // at top with includes/defines, replaces regular version: CRGB leds[NUM_LEDS];
  32. B. Include animation code in onLateLoop()
  33.     Two if statements to turn effect on and off
  34. C. Add boolean to onOffCustomEventOnOffChanged
  35.  
  36.     Example:
  37.  
  38.     if (strcmp(effectorIdentifier, "Eyes") == 0) {  
  39.     Eyes_on = !Eyes_on;
  40.   }
  41. D. Setup code in onThisControllerStarted covers the entire strip, even if using CRGBSet.
  42. */
  43.  
  44. // Details:
  45.  
  46. // Add this code to BottangoArduinoCallbacks.cpp
  47. // At top below other Includes, set up FastLED:
  48.  
  49. // FastLED setup:
  50. #include "FastLED.h"
  51. #define DATA_PIN 14
  52. #define LED_TYPE NEOPIXEL
  53. #define COLOR_ORDER GRB
  54. #define NUM_LEDS 8
  55. #define BRIGHTNESS 75
  56. CRGB leds[NUM_LEDS];
  57.  
  58. // Or this if using long string of Neopixels and addressing part of them with CRGBSet:
  59. CRGBArray<NUM_LEDS> leds;
  60.  
  61. bool Cylon_animating = false;  // Controls FastLED effect on/off
  62.  
  63. // Initialize FastLED when controller boots up
  64.  
  65. void onThisControllerStarted() {
  66.   FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);  
  67.   FastLED.setBrightness(BRIGHTNESS);
  68. }
  69.  
  70. // Animation code
  71. // To control the animation, the main code from a regular FastLED loop() is moved to onLateLoop()
  72. // Bottango looks for bool (such as Cylon_animating) to be set to True and if Yes, then runs the animation.
  73. // Note - handle both on and off conditions.
  74.  
  75. void onLateLoop() {
  76.  
  77.   if (Cylon_animating == true) {   
  78.     FastLED.setBrightness(BRIGHTNESS);            // 0 - 255, 8-bit
  79.     uint16_t i = beatsin16(25, 0, NUM_LEDS - 1);  // 25 in this is how many beats per minute
  80.     leds[i] = CRGB::Blue;
  81.  
  82.     FastLED.show();
  83.     fadeToBlackBy(leds, NUM_LEDS, 8);
  84.   }
  85.  
  86.   // If bool is False, then turn off all Neopixels
  87.   if (Cylon_animating == false) {
  88.     for (int i = 0; i < NUM_LEDS; ++i) {  // All off
  89.     leds[i] = CRGB::Black;
  90.     FastLED.show();
  91.         }
  92.     }
  93. }
  94.  
  95. // Turn on or off the FastLED animation state
  96. // This is controlled by the On/Off event in the Bottango UI
  97.  
  98. void onOnOffCustomEventOnOffChanged(AbstractEffector *effector, bool on) {
  99.  
  100.   char effectorIdentifier[9];
  101.   effector->getIdentifier(effectorIdentifier, 9);
  102.  
  103.   if (strcmp(effectorIdentifier, "Cylon") == 0) {       // Edit the Identifier ("Cylon") to match On/Off event
  104.     Cylon_animating = !Cylon_animating;
  105.   }  
  106. }
  107.  
  108.  
  109. // Changing the color of FastLED pixels
  110. // Details of onColorCustomEventColorChanged
  111. // Initialization is in onThisControllerStarted
  112. // No need for boolean or any code in onLateLoop, it's handled in onColorCustomEventColorChanged
  113.  
  114. void onColorCustomEventColorChanged(AbstractEffector* effector, byte newRed, byte newGreen, byte newBlue) {
  115.   // 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)
  116.   char effectorIdentifier[9];
  117.   effector->getIdentifier(effectorIdentifier, 9);
  118.  
  119.   if (strcmp(effectorIdentifier, "eyeColor") == 0) {
  120.     CRGBSet firstTwo(leds(0, 1));       // Addresses the first two pixels of the strand
  121.     fill_solid(firstTwo, 2, CRGB(newRed, newGreen, newBlue));  // The "2" is just the first two, for the eyes
  122.     FastLED.show();
  123.   }
  124. }
Tags: FastLED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement