Advertisement
shaolinsolidus

Untitled

Jun 29th, 2015
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.38 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. #include <LEDMatrix.h>
  4. #include <LEDText.h>
  5. #include <FontRobotron.h>
  6.  
  7. #define LED_PIN 6
  8. #define BRIGHTNESS 64
  9. #define LED_TYPE WS2812B
  10. #define COLOR_ORDER GRB
  11.  
  12. #define UPDATES_PER_SECOND 100
  13.  
  14. #define MATRIX_WIDTH 28 // Set this negative if physical led 0 is opposite to where you want logical 0
  15. #define MATRIX_HEIGHT 7 // Set this negative if physical led 0 is opposite to where you want logical 0
  16. #define MATRIX_TYPE VERTICAL_ZIGZAG_MATRIX // See top of LEDMatrix.h for matrix wiring types
  17.  
  18. cLEDMatrix<MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_TYPE> leds;
  19. cLEDText ScrollingMsg;
  20.  
  21.  
  22.  
  23. // This example shows several ways to set up and use 'palettes' of colors
  24. // with FastLED.
  25. //
  26. // These compact palettes provide an easy way to re-colorize your
  27. // animation on the fly, quickly, easily, and with low overhead.
  28. //
  29. // USING palettes is MUCH simpler in practice than in theory, so first just
  30. // run this sketch, and watch the pretty lights as you then read through
  31. // the code. Although this sketch has eight (or more) different color schemes,
  32. // the entire sketch compiles down to about 6.5K on AVR.
  33. //
  34. // FastLED provides a few pre-configured color palettes, and makes it
  35. // extremely easy to make up your own color schemes with palettes.
  36. //
  37. // Some notes on the more abstract 'theory and practice' of
  38. // FastLED compact palettes are at the bottom of this file.
  39.  
  40.  
  41.  
  42. CRGBPalette16 currentPalette;
  43. TBlendType currentBlending;
  44.  
  45. extern CRGBPalette16 myRedWhiteBluePalette;
  46. extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
  47.  
  48.  
  49. void setup() {
  50. delay( 3000 ); // power-up safety delay
  51. FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds[0], leds.Size()).setCorrection( TypicalLEDStrip );
  52. FastLED.setBrightness( BRIGHTNESS );
  53.  
  54. currentPalette = RainbowColors_p;
  55. currentBlending = BLEND;
  56.  
  57. ScrollingMsg.Init(&leds, MATRIX_WIDTH, MATRIX_HEIGHT + 1, 0, 0);
  58. ScrollingMsg.SetFont(RobotronFontData);
  59.  
  60. }
  61.  
  62. void loop()
  63. {
  64. static uint16_t myCount = 0;
  65. static uint8_t myMode = 0;
  66. if (myMode == 0)
  67. {
  68.  
  69. ChangePalettePeriodically();
  70.  
  71. static uint8_t startIndex = 0;
  72. startIndex = startIndex + 1; /* motion speed */
  73.  
  74. FillLEDsFromPaletteColors( startIndex);
  75.  
  76. if (ScrollingMsg.UpdateText() == -1)
  77. {
  78. ScrollingMsg.UpdateText();
  79. }
  80.  
  81. FastLED.show();
  82. FastLED.delay(1000 / UPDATES_PER_SECOND);
  83.  
  84.  
  85. }
  86. else
  87. {
  88.  
  89. EFFECT_COLR_EMPTY EFFECT_BACKGND_ERASE
  90. " THIS IS A SCROLLING MESSAGE! "
  91. ; }
  92. myCount++;
  93. if (myCount >= 1500)
  94. {
  95. myMode++;
  96. if (myMode >= 2)
  97. myMode = 0;
  98. }
  99. }
  100.  
  101.  
  102.  
  103. void FillLEDsFromPaletteColors( uint8_t colorIndex)
  104. {
  105. uint8_t brightness = 255;
  106.  
  107. for( int i = 0; i < leds.Size(); i++) {
  108. *(leds[i]) = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
  109. colorIndex += 3;
  110. }
  111. }
  112.  
  113.  
  114. // There are several different palettes of colors demonstrated here.
  115. //
  116. // FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
  117. // OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
  118. //
  119. // Additionally, you can manually define your own color palettes, or you can write
  120. // code that creates color palettes on the fly. All are shown here.
  121.  
  122. void ChangePalettePeriodically()
  123. {
  124. uint8_t secondHand = (millis() / 1000) % 60;
  125. static uint8_t lastSecond = 99;
  126.  
  127. if( lastSecond != secondHand) {
  128. lastSecond = secondHand;
  129. if( secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = BLEND; }
  130. if( secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; }
  131. if( secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = BLEND; }
  132. if( secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = BLEND; }
  133. if( secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = BLEND; }
  134. if( secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; }
  135. if( secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = BLEND; }
  136. if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = BLEND; }
  137. if( secondHand == 45) { currentPalette = PartyColors_p; currentBlending = BLEND; }
  138. if( secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; }
  139. if( secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = BLEND; }
  140. }
  141. }
  142.  
  143. // This function fills the palette with totally random colors.
  144. void SetupTotallyRandomPalette()
  145. {
  146. for( int i = 0; i < 16; i++) {
  147. currentPalette[i] = CHSV( random8(), 255, random8());
  148. }
  149. }
  150.  
  151. // This function sets up a palette of black and white stripes,
  152. // using code. Since the palette is effectively an array of
  153. // sixteen CRGB colors, the various fill_* functions can be used
  154. // to set them up.
  155. void SetupBlackAndWhiteStripedPalette()
  156. {
  157. // 'black out' all 16 palette entries...
  158. fill_solid( currentPalette, 16, CRGB::Black);
  159. // and set every fourth one to white.
  160. currentPalette[0] = CRGB::White;
  161. currentPalette[4] = CRGB::White;
  162. currentPalette[8] = CRGB::White;
  163. currentPalette[12] = CRGB::White;
  164.  
  165. }
  166.  
  167. // This function sets up a palette of purple and green stripes.
  168. void SetupPurpleAndGreenPalette()
  169. {
  170. CRGB purple = CHSV( HUE_PURPLE, 255, 255);
  171. CRGB green = CHSV( HUE_GREEN, 255, 255);
  172. CRGB black = CRGB::Black;
  173.  
  174. currentPalette = CRGBPalette16(
  175. green, green, black, black,
  176. purple, purple, black, black,
  177. green, green, black, black,
  178. purple, purple, black, black );
  179. }
  180.  
  181.  
  182. // This example shows how to set up a static color palette
  183. // which is stored in PROGMEM (flash), which is almost always more
  184. // plentiful than RAM. A static PROGMEM palette like this
  185. // takes up 64 bytes of flash.
  186. const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
  187. {
  188. CRGB::Red,
  189. CRGB::Gray, // 'white' is too bright compared to red and blue
  190. CRGB::Blue,
  191. CRGB::Black,
  192.  
  193. CRGB::Red,
  194. CRGB::Gray,
  195. CRGB::Blue,
  196. CRGB::Black,
  197.  
  198. CRGB::Red,
  199. CRGB::Red,
  200. CRGB::Gray,
  201. CRGB::Gray,
  202. CRGB::Blue,
  203. CRGB::Blue,
  204. CRGB::Black,
  205. CRGB::Black
  206. };
  207.  
  208.  
  209.  
  210. // Additionl notes on FastLED compact palettes:
  211. //
  212. // Normally, in computer graphics, the palette (or "color lookup table")
  213. // has 256 entries, each containing a specific 24-bit RGB color. You can then
  214. // index into the color palette using a simple 8-bit (one byte) value.
  215. // A 256-entry color palette takes up 768 bytes of RAM, which on Arduino
  216. // is quite possibly "too many" bytes.
  217. //
  218. // FastLED does offer traditional 256-element palettes, for setups that
  219. // can afford the 768-byte cost in RAM.
  220. //
  221. // However, FastLED also offers a compact alternative. FastLED offers
  222. // palettes that store 16 distinct entries, but can be accessed AS IF
  223. // they actually have 256 entries; this is accomplished by interpolating
  224. // between the 16 explicit entries to create fifteen intermediate palette
  225. // entries between each pair.
  226. //
  227. // So for example, if you set the first two explicit entries of a compact
  228. // palette to Green (0,255,0) and Blue (0,0,255), and then retrieved
  229. // the first sixteen entries from the virtual palette (of 256), you'd get
  230. // Green, followed by a smooth gradient from green-to-blue, and then Blue.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement