Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. #include "Arduino.h"
  2. #include <FastLED.h>
  3. FASTLED_USING_NAMESPACE
  4.  
  5. #define NUM_LEDS 60
  6.  
  7. CRGB rawleds[NUM_LEDS];
  8.  
  9. const int virtualleds[10]
  10. { 2,  // 1
  11.   7,  // 2
  12.   0,  // 3
  13.   4,  // 4
  14.   12, // 5
  15.   3,  // 6
  16.   11, // 7
  17.   1,  // 8
  18.   15, // 9
  19.   13 // 10
  20. } ;
  21.  
  22. #define BRIGHTNESS         100
  23. #define FRAMES_PER_SECOND  120
  24.  
  25. void rainbow();
  26.  
  27. void my_fill_rainbow( struct CRGB * pFirstLED, int numToFill, int *virtualleds,
  28.                   uint8_t initialhue,
  29.                   uint8_t deltahue );
  30.  
  31. void setup()
  32. {
  33.   // initialize LED digital pin as an output.
  34.    FastLED.addLeds<NEOPIXEL, 6>(rawleds, NUM_LEDS);
  35.    FastLED.setBrightness(BRIGHTNESS);
  36. }
  37.  
  38. uint8_t gHue = 0; // rotating "base color" used by many of the patterns
  39.  
  40. void loop()
  41. {
  42.  
  43.   // send the 'leds' array out to the actual LED strip
  44.   FastLED.show();
  45.   // insert a delay to keep the framerate modest
  46.   FastLED.delay(1000/FRAMES_PER_SECOND);
  47.  
  48.   // do some periodic updates
  49.   EVERY_N_MILLISECONDS( 1 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  50.   rainbow();
  51. }
  52.  
  53.  
  54. void rainbow()
  55. {
  56.   // my modified FastLED's built-in rainbow generator
  57.   my_fill_rainbow( rawleds, 10, virtualleds, gHue, 7);
  58. }
  59.  
  60. void my_fill_rainbow( struct CRGB * pFirstLED, int numToFill, int *virtualleds,
  61.                   uint8_t initialhue,
  62.                   uint8_t deltahue )
  63. {
  64.     CHSV hsv;
  65.     hsv.hue = initialhue;
  66.     hsv.val = 255;
  67.     hsv.sat = 240;
  68.     for( int i = 0; i < numToFill; i++) {
  69.         int virtualled=virtualleds[i];
  70.         pFirstLED[virtualled] = hsv;
  71.         hsv.hue += deltahue;
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement