kriegsman

Using a 256-element PROGMEM array as a palette

Feb 7th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.69 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #define LED_PIN     4
  4. #define NUM_LEDS    256
  5. #define BRIGHTNESS  64
  6. #define LED_TYPE    WS2812
  7. #define COLOR_ORDER GRB
  8. CRGB leds[NUM_LEDS];
  9.  
  10. #define UPDATES_PER_SECOND 100
  11.  
  12.  
  13. void setup()
  14. {
  15.   delay( 3000 ); // power-up safety delay
  16.   FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  17.   FastLED.setBrightness(  BRIGHTNESS );
  18. }
  19.  
  20.  
  21. void loop()
  22. {
  23.   static uint8_t startIndex = 0;
  24.   //startIndex = startIndex + 1; /* motion speed */
  25.    
  26.   FillLEDsFromMyColors( startIndex);
  27.  
  28.   FastLED.show();
  29.   FastLED.delay(1000 / UPDATES_PER_SECOND);
  30. }
  31.  
  32.  
  33. void FillLEDsFromMyColors( uint8_t colorIndex)
  34. {
  35.   for( int i = 0; i < NUM_LEDS; i++) {
  36.     leds[i] = ColorFromMyColors( colorIndex);
  37.     colorIndex += 1;
  38.   }
  39. }
  40.  
  41.  
  42. // forward declaration of 'myColors', which comes later
  43. extern const uint32_t myColors[] PROGMEM;
  44.  
  45. // function to return a color from the PROGMEM color array,
  46. // sort of like ColorFromPalette.
  47. CRGB ColorFromMyColors( uint8_t index)
  48. {
  49.   CRGB color = myColors[ index ];
  50.   return color;
  51. }
  52.  
  53.  
  54. const uint32_t myColors[] PROGMEM = {
  55.  0x49538E, 0x242565, 0x362247, 0x231609, 0x3C2978, 0x59439D, 0x5E4C94, 0x4E3776,
  56.  0x021517, 0x00273F, 0x64221C, 0x974017, 0x1E2420, 0x071928, 0x061632, 0x000629,
  57.  0x00042E, 0x002754, 0x33312A, 0xA16203, 0xD67F03, 0x6C4E1B, 0x061B29, 0x042738,
  58.  0x08233E, 0x070921, 0x000B26, 0x19252C, 0x141E24, 0x17263B, 0x2E6866, 0x457F33,
  59.  0x37531C, 0x06000A, 0x28290B, 0x2B452A, 0x0A2E48, 0x1F3134, 0x484435, 0x112547,
  60.  0x001A2C, 0x865E01, 0xBF6C00, 0x7B490A, 0x3D2B1F, 0x283625, 0x5C614B, 0x3B515E,
  61.  0x000A37, 0x385213, 0x6C880A, 0x042325, 0x000C17, 0x01150F, 0x070F0A, 0x223C4B,
  62.  0x457D96, 0x4793AB, 0x0C313A, 0x000000, 0x143D4B, 0x479ABF, 0x579AB2, 0x1D3140,
  63.  0x076092, 0x2C8CBC, 0x274B65, 0x121F21, 0x0F0D07, 0x14320E, 0x2E270E, 0x57380B,
  64.  0x243F0F, 0x23290E, 0x061517, 0x000F0D, 0x1A0A07, 0x780D07, 0x5C0002, 0x000F09,
  65.  0x010D09, 0x030807, 0x010504, 0x000300, 0x010A0A, 0x43646B, 0x4491BE, 0x4B7068,
  66.  0x1D2400, 0x00110F, 0x001805, 0x082003, 0x080E07, 0x000003, 0x010708, 0x012A19,
  67.  0x022313, 0x073817, 0x003617, 0x12270E, 0x241E08, 0x024B16, 0x037127, 0x116122,
  68.  0x15601C, 0x426B19, 0x506D0C, 0x186318, 0x005424, 0x1A6425, 0x758716, 0x698211,
  69.  0x78890B, 0x7B6506, 0x556071, 0x456AB1, 0x3F5660, 0x445467, 0x403387, 0x3660AC,
  70.  0x1F66A1, 0x2E4F9B, 0x284AA4, 0x3068B1, 0x0E65A9, 0x0165B0, 0x0F66B0, 0x0568AA,
  71.  0x0972B3, 0x0B79B0, 0x0571AD, 0x2176A3, 0x184E8A, 0x035C9A, 0x3B90B1, 0x93D2C4,
  72.  0x69808D, 0x3C3063, 0x8BB9CC, 0xB2D7D6, 0xA3C4CE, 0x6C688F, 0xA4B4C0, 0xB0C8BA,
  73.  0xB0B6A9, 0x675145, 0x829498, 0xB1DCE4, 0x6D8673, 0x61888D, 0x5F6954, 0x3D423E,
  74.  0x3C506E, 0x61656A, 0x826A47, 0x443A37, 0x5E686A, 0x91926B, 0x916217, 0xD17E29,
  75.  0x95746B, 0xBA9338, 0xBE6320, 0xBB4E49, 0xB8645D, 0xE08441, 0xD7994C, 0xE1B76D,
  76.  0xC79230, 0xA76312, 0xB75343, 0xB6583B, 0x9B630D, 0x9A3800, 0xAE6854, 0xC3C2A4,
  77.  0x918451, 0xA5A792, 0xA7A48A, 0xBDA45E, 0xC09538, 0x968952, 0x4F5531, 0x441820,
  78.  0x483142, 0x1C3034, 0x3F1607, 0x4E4D66, 0x00315F, 0x030000, 0x2F3044, 0x28334C,
  79.  0x181E28, 0x333D4F, 0x07193F, 0x011130, 0x062249, 0xA2B0C5, 0xAEB9B9, 0x4E705A,
  80.  0x0E272B, 0x020100, 0x1C1929, 0x182A46, 0x041423, 0x000002, 0x000000, 0x000009,
  81.  0x03081C, 0x040200, 0x152B55, 0x1B2F59, 0x304F8A, 0x204B8A, 0x53599A, 0x8663A7,
  82.  0x4D508D, 0x4968AC, 0x414A6D, 0x181617, 0x0D0F22, 0x0F1437, 0x181A3C, 0x1B253B,
  83.  0x283119, 0x342603, 0x293130, 0x31355A, 0x4C2F36, 0x5C3331, 0x342721, 0x2B210B,
  84.  0x282726, 0x151835, 0x150E29, 0x72554A, 0x531121, 0x642605, 0xC36F0C, 0xAB4E19,
  85.  0x54211D, 0x20000B, 0x4B1002, 0x2A1B3A, 0x1B367F, 0x121550, 0x31194A, 0x542F42,
  86.  0x4E364F, 0x2E1C4F, 0x221124, 0x37396C, 0x37396C, 0x37396C, 0x37396C, 0x37396C
  87. };
Advertisement
Add Comment
Please, Sign In to add comment