Go Down

Topic: 16x16 Matrix, message and rain code, help. (Read 324 times) previous topic - next topic

rigovargas

Jun 05, 2019, 05:18 am Last Edit: Jun 07, 2019, 05:11 pm by rigovargas
Hi,  Need some help.  Newbie, I have some code to display random pixels on-off (rain) and I have a message that want to display after the rain or before.  however it seems that the message does not scroll correctly.  I am attaching code hopefully a genius could guide me in the right direction.



Code: [Select]


#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

// DATA PIN
// If you want to use a different data pin on your microcontroller CHANGE THIS!
#define DATA_PIN 6

//used for long message
#define arr_len( x )  ( sizeof( x ) / sizeof( *x ) )

// Matrix setup params
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(16, 16, DATA_PIN,
NEO_MATRIX_TOP    + NEO_MATRIX_RIGHT +
NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE + NEO_MATRIX_ZIGZAG,
NEO_GRB            + NEO_KHZ800);


// Edit this
// The important stuff, your message and colors

char* Text[]= {"Hello Friends","Welcome To","Need","some","help.","please"," could,","use,","your services"};
const uint16_t colors[] = {
  matrix.Color(255, 0, 255), matrix.Color(100, 255, 0), matrix.Color(255, 255, 0),matrix.Color(0, 0, 255), matrix.Color(255, 0, 255), matrix.Color(0, 255, 255), matrix.Color(255, 255, 255)};
int brightness = 10;
// End Edit

int numMode = arr_len(Text)-1;
int numColor = arr_len(colors)-1;
int pixelPerChar = 4;
int maxDisplacement;
int mode = 0;

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(brightness);
  matrix.setTextColor(colors[0]);
}

int y = 16;
int x = 16;
int pass = 0;
int line_pass = 0;

void loop() {
    
  // if mode greater than numMode reset
  if (mode > numMode) { mode = 0; }
  
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  scroll(Text[mode],10);
  
   //delay(300);
    rain(5, 20);
}
void clear() {
  for(int i=0;i<256;i++){
    matrix.setPixelColor(i, matrix.Color(0,0,0));
  }
}
// this does the magic of scrolling
void scroll(char* message,int delays) {
  maxDisplacement = strlen(message) * pixelPerChar + matrix.width();
  if(++line_pass > matrix.width()) line_pass = 0;
  matrix.print(String(message));
  if(--x < -maxDisplacement) {
    x = matrix.width();
    if(++pass >= numColor) { pass = 0;  };
    matrix.setTextColor(colors[pass]);
    mode++;
  }
  matrix.show();
  delay(delays);
}

//rain
void rain(int cycles, int delayTime) {
  int rain[] = {0,0,0,0,0,0,0,0};
  int values[] = {0,0,0,0,0,0,0,0};

  for (int v=0; v<16; v++) {
    values[v] = random(0, 10) * 10;
  }

  for (int c=0; c<cycles; c++) {
    for (int f=0; f<10; f++) {
      for (int col = 0; col < 16; col++) {
        int row = map(values[col], 0, 100, 0, 16);
        if ((row % 2) == 1) {
          matrix.setPixelColor((256-row*16)+(7-col), matrix.Color(200,200,200));
        } else {
          matrix.setPixelColor((256-row*16)+col, matrix.Color(200,200,200));
        }
      }
      
     matrix.show();
      delay(delayTime);
      
      for (int v=0; v<16; v++) {
        values[v] = (values[v] + 10) % 100;
      }
      
      matrix.clear();
      delay(100);
     }
   }
}




Go Up