bagges / rgb_wordclock

Wordclock based on the popular WS2812B RGB LED strips
GNU General Public License v3.0
14 stars 8 forks source link

"Matrix style" and running text #1

Open georg90 opened 9 years ago

georg90 commented 9 years ago

Any ideas on supporting a "Matrix" style (from the movies)?

I edited your code a little to be able to run without a DCF77, getting an ACK on remote commands and setting the time with the remote. Also I like to get a Matrix style display and "running text".

I found this for Matrix style operation:

// Matrix Mode defines
#define MATRIX_MIN_LENGTH 3
#define MATRIX_UPDATE_INTERVAL 250
long int lastMillis = 0;
long int currentMillis;
word matrixBegin = 0;
short matrixLength = 99;

void showMatrix() {
   currentMillis = millis();
      if (currentMillis - lastMillis > MATRIX_UPDATE_INTERVAL) {
        lastMillis  = currentMillis;

        if(matrixLength >= MATRIX_MIN_LENGTH && random(1,100) > 60) {
          matrixBegin = random(0b0000000000000000, 0b1010011010100000);
          matrixBegin &= random(0b0000000000000000, 0b1010011010100000);
          matrixBegin &= 0b1111111111100000; // remove corner LEDs
          matrixLength = 0;
        }
        matrixLength++;
        // move old line 1 line down
        for(int i = 10; i >= 1; i--) {
          matrix[i] = matrix[i-1]; 
        }
        // set new top line
        matrix[0] = matrixBegin;
      }
      needsUpdateFromRtc = true;
      break;
}

Any idea how to edit this to fit the numbering with your setup?

If anybody is interested I can upload the code soon..

bagges commented 9 years ago

I have some code for the "matrix" style on my hdd. I will search for it and commit it to an experimental branch.

georg90 commented 9 years ago

Sounds Great - I thought something like this has to be implemented already ;-)

bagges commented 9 years ago

Here is the code I found on my hdd. I think this is not even finished but should be a good starting point. Unfortunately I do not have the time to integrate it :-/. If you add this feature, I would appreciate a pull request :-)

#include "FastLED.h"

#define NUM_LEDS 114
#define DATA_PIN 6
CRGB leds[NUM_LEDS] = {CRGB::Red};

void setup() { 
    FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
    Serial.begin(9600);
}

uint8_t shiftInCols[11] = {0,0,0,5,0,0,0,3,0,0,8};
uint16_t matrixCols[11] = {0,0,0,0,0,0,0,0,0,0,0};

void refreshMatrix() {

    Serial.println("refresh()");

    for(char i=0; i<11; i++) {

        matrixCols[i] <<= 1;

        if(shiftInCols[i] > 0) {
            matrixCols[i] |= 1;
            shiftInCols[i]--;
        }
        else {

            if(random(0,6) == 0) {
                shiftInCols[i] = random(3,7);
                //matrixCols[i] |= 1;
            }
        }
    }
}

uint8_t posToNum(uint8_t col, uint8_t row) {

    uint8_t ret = 0;
    row = 9 - row;

    if((col & 1) != 0) {
        // gerade spalten
        ret += (9 - row);
    } else { 
        ret += row;
    }

    ret += (10*col);
    return ret;
} 

void prepareBuffer() {

    Serial.println("prepare()");

    for(char col=0; col<11; col++) {
        for(char row=0; row<10; row++) {

            const uint16_t mask = (1 << row);
            uint8_t num = posToNum(col, row);

            if(num >= NUM_LEDS) {
                num = 0;
            }
            if((matrixCols[col] & mask) != 0) {
                leds[num] = CRGB::Green;
            }
            else {
                leds[num] = CRGB::Black;
            }

        }
    }
}

void loop() { 
  Serial.println("loop");
  refreshMatrix();

  prepareBuffer();

  FastLED.show();
  delay(200);
}
georg90 commented 9 years ago

thanks for the snippet! I'll post my results once I get started

georg90 commented 9 years ago

this will work without customizing - just edit it to run into the main sketch and you're done.

Macci0 commented 8 years ago

Hi Georg, i'm interested on your Code. Can you share it please? Thanks a lot for your Help.

I edited your code a little to be able to run without a DCF77, getting an ACK on remote commands and setting the time with the remote.