willhartley

FastLED Text Scroll

Feb 26th, 2020 (edited)
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //For ATmega32u4
  2. //My matrix is setup 3 x 35 (3 Rows, 35 LEDs wide
  3. //Text is being flipped in a different matrix to scroll from left to right.
  4.  
  5. #include <avr/pgmspace.h>                     //Needed to store stuff in Flash using PROGMEM
  6. #include <EEPROM.h>                           //Needed to store variables in memory to persist after power off.
  7. #include <FastLED.h>                          //Fastled library to control the LEDs
  8.  
  9. #define MAX_BRIGHT  40
  10. #define LED_PIN     3
  11. #define LED_TYPE    WS2812B
  12. #define COLOR_ORDER GRB
  13. #define NUM_LEDS 105
  14. CRGB leds[NUM_LEDS];
  15.  
  16. // Params for width and height (work to replace)
  17. const uint8_t kMatrixWidth = 11;  //orig 11x27
  18. const uint8_t kMatrixHeight = 27; //(can try 3x25 for 75 leds) or (3*20 for 60)
  19.  
  20. int Start = 0;
  21. int End = 35;
  22.  
  23. byte text_r1[] = {0,0,0,0,0,0,1,1,1,0,0,1,1,1,0,0,0,1,1,0,0,1,1,1,0,0,0,0,0,0};
  24. byte text_r2[] = {0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0};
  25. byte text_r3[] = {0,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0};
  26.  
  27. int array_len = sizeof(text_r1) / sizeof(text_r1[0]); //since all rows are even, only need to do this once
  28.  
  29.  
  30. void setup() {
  31.   //Serial.begin(9600);
  32.   delay(1500);    //Startup power delay. 1.5 seconds.
  33.   FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  34.   FastLED.setMaxPowerInVoltsAndMilliamps(5,800);
  35.   FastLED.setBrightness(MAX_BRIGHT);
  36.   fill_solid(leds, NUM_LEDS, CRGB::Black);
  37.   FastLED.show();
  38.  
  39. //Flip the arrays for the display.
  40.   for(int h=0;h<array_len;h++){
  41.     byte temp;
  42.     temp = text_r1[h];
  43.     text_r1[h] = text_r1[array_len-h-1];
  44.     text_r1[array_len-h-1] = temp;    
  45.   }
  46.  
  47.     for(int i=0;i<array_len;i++){
  48.     byte temp;
  49.     temp = text_r2[i];
  50.     text_r2[i] = text_r2[array_len-i-1];
  51.     text_r2[array_len-i-1] = temp;    
  52.   }
  53.  
  54.     for(int j=0;j<array_len;j++){
  55.     byte temp;
  56.     temp = text_r3[j];
  57.     text_r3[j] = text_r3[array_len-j-1];
  58.     text_r3[array_len-j-1] = temp;    
  59.   }
  60.  
  61. }
  62.  
  63. void loop() {
  64.   text_scroll();
  65. }
  66.  
  67. void text_scroll(){
  68.  
  69.   FastLED.clear();
  70.   int next = Start;
  71.   int i = 0;
  72.   while(true) {    
  73.     if (text_r1[next]==1)
  74.       leds[i] = CRGB::Red;
  75.     if (text_r2[next]==1)
  76.       leds[i+35] = CRGB::Red;
  77.     if (text_r3[next]==1)
  78.       leds[i+70] = CRGB::Red;
  79.  
  80.     i++;
  81.     next = next+1;
  82.     if (next == 57)
  83.       next = 0;
  84.     if (next == End)
  85.       break;
  86.   }
  87.  
  88.   if (Start == 0){
  89.     Start = 56;
  90.   }
  91.     else
  92.     {
  93.     Start = Start - 1;
  94.     }
  95.   if (End == 0)
  96.   {
  97.     End = 56;
  98.   }
  99.     else
  100.     {
  101.     End = End-1;
  102.     }
  103.   //Serial.print(Start);
  104.   //Serial.print(" ");
  105.   //Serial.print(End);
  106.   //Serial.print("\n");
  107.  
  108.  
  109.   delay(130);
  110.   FastLED.show();
  111. }
Add Comment
Please, Sign In to add comment