Guest User

MavicRGB mod

a guest
Dec 10th, 2017
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.41 KB | None | 0 0
  1. #include "FastLED.h"
  2. // Number of RGB LEDs in the strand
  3. #define NUM_LEDS 20
  4.  
  5. // Define the array of leds
  6. CRGB leds[NUM_LEDS];
  7. // Arduino pin used for Data
  8. //#define PIN 13
  9. #define PIN 2
  10. #define FRAMES_PER_SECOND  120
  11. byte anim_count =0;
  12.  
  13.  
  14. void setup()
  15. {
  16.   FastLED.addLeds<NEOPIXEL, PIN>(leds, NUM_LEDS);
  17.   FastLED.setBrightness(40);
  18.   boot_animation();
  19. }
  20.  
  21.  
  22. // List of patterns to cycle through.  Each is defined as a separate function below.
  23. typedef void (*SimplePatternList[])();
  24. //SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, sinelon, juggle };
  25. SimplePatternList gPatterns = {  rainbow, sinelon, sinelon1way};
  26.  
  27.  
  28. uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
  29. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  30.  
  31. void loop()
  32. {
  33.   // Call the current pattern function once, updating the 'leds' array
  34.   gPatterns[gCurrentPatternNumber]();
  35.  
  36.   // send the 'leds' array out to the actual LED strip
  37.   FastLED.show();  
  38.   // insert a delay to keep the framerate modest
  39.   FastLED.delay(1000/FRAMES_PER_SECOND);
  40.  
  41.   // do some periodic updates
  42.   EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  43.   EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
  44. }
  45.  
  46. #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
  47.  
  48. void nextPattern()
  49. {
  50.   // add one to the current pattern number, and wrap around at the end
  51.   gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
  52. }
  53.  
  54. void rainbow()
  55. {
  56.   // FastLED's built-in rainbow generator
  57.   fill_rainbow( leds, NUM_LEDS, gHue, 7);
  58. }
  59.  
  60. /*
  61. void rainbowWithGlitter()
  62. {
  63.   // built-in FastLED rainbow, plus some random sparkly glitter
  64.   rainbow();
  65.   addGlitter(80);
  66. }
  67.  
  68. void addGlitter( fract8 chanceOfGlitter)
  69. {
  70.   if( random8() < chanceOfGlitter) {
  71.     leds[ random16(NUM_LEDS) ] += CRGB::White;
  72.   }
  73. }
  74. */
  75.  
  76. void sinelon()
  77. {
  78.   // a colored dot sweeping back and forth, with fading trails
  79.   fadeToBlackBy( leds, NUM_LEDS, 20);
  80.   uint8_t pos = beatsin16(20,0,NUM_LEDS/2 );
  81.   leds[pos] += CHSV( gHue, 255, 192);
  82.   leds[pos + NUM_LEDS/2] += CHSV( gHue, 255, 192);
  83. }
  84. void sinelon1way(){
  85.   // a colored dot sweeping forth, with fading trails
  86.   fadeToBlackBy( leds, NUM_LEDS, 20);
  87.   uint8_t pos = ((millis() / 70) % NUM_LEDS/2 );
  88.   leds[pos] += CHSV( gHue, 255, 192);
  89.   leds[pos + NUM_LEDS/2] += CHSV( gHue, 255, 192);
  90.  
  91. }
  92.  
  93. void boot_animation(){
  94.   //red booting blinking
  95.   for(int l = 0; l < 20 ; l++) {
  96.     if(l % 2){  
  97.       for(byte i = 0 ; i < NUM_LEDS; i++){
  98.         leds[i] = CRGB(255,0,0);
  99.       }
  100.       FastLED.show();
  101.       delay(250);
  102.     }
  103.     else{
  104.       FastLED.clear();
  105.       FastLED.show();
  106.       delay(250);
  107.     }
  108.    
  109.   }
  110.   while(1){
  111.   uint8_t pos = ((millis() / 70) % NUM_LEDS/2 );
  112.   if (anim_count < 1){
  113.     leds[pos] += CRGB(255,0,0);
  114.     leds[pos + NUM_LEDS/2] += CRGB(255,0,0);
  115.   }
  116.   else{
  117.     leds[pos] += CRGB(0,255,0);
  118.     leds[pos + NUM_LEDS/2] += CRGB(0,255,0);
  119.   }
  120.   if(anim_count == 3)
  121.     break;
  122.  
  123.   fadeToBlackBy( leds, NUM_LEDS, 15);
  124.   FastLED.show();  
  125.   // insert a delay to keep the framerate modest
  126.   FastLED.delay(1000/FRAMES_PER_SECOND);
  127.   EVERY_N_SECONDS( 10 ) { anim_count++; }
  128.   }
  129.   for(byte i = 0 ; i < NUM_LEDS; i++){
  130.         leds[i] = CRGB(0,255,0);
  131.   }
  132.   FastLED.show();
  133.   delay(2000);
  134.   FastLED.clear();
  135.   FastLED.show();
  136.   delay(1000);
  137. }
Advertisement
Add Comment
Please, Sign In to add comment