Go Down

Topic: millis() with Max7219 (Read 236 times) previous topic - next topic

sendHelpPls

May 09, 2019, 10:39 pm Last Edit: May 09, 2019, 10:55 pm by sendHelpPls
Hello everyone i have a problem.

I am building a Clock with Alarm and i want to use 3 of the Max Matrix to show the time, date and scrolling text messages or bigger information.

The problem is, the functions for scrolling messages i have coppied from the MAXMATRIX examples are using the delay() function to simulate a text floating one pixel to the left every amount of milliseconds u have declared. (Functions are at bottom of the code)

It works fine but as soon as i build in a push button to switch between the modes of static time, date and scrolling message, there is this delay of the function which forces you to press the button till the interval of one full scroll is finished. You all know the problem with the delay function...

I tried and errored probably 100 times and i still cant get the function to work with millis(), i dont know what i am doing wrong :(

and another thing that i cant get to work is a rotating double dot animation for the static time, youll see in the code what crap i wrote there :D maybe someone has a solution for this problem too, thanks

i hope someone is out there who can help me because i have to finish this project for school in three weeks.

kind regards johnny

Code: [Select]

#include <Arduino.h>     
#include <DS3231.h>
#include <Wire.h>
#include <MaxMatrix.h>


const byte PROGMEM CH[] = { TOO BIG TO PUT IN THIS POST;
                                          I POST IT IN THE FIRST ANSWER TO THIS POST}

int dataPIN = 8;    // DIN pin of MAX7219 module
int loadPIN = 9;    // CS pin of MAX7219 module
int clockPIN = 10;  // CLK pin of MAX7219 module

MaxMatrix m(dataPIN, loadPIN, clockPIN, 3);
byte buffer[100];

DS3231 clock;
RTCDateTime now;

int mode = 0;
unsigned long prevMillis;
const int interval = 75;
int time1, time2, time3, time4, time5, time6, time7, time8;

char actTime[6];
char actDatum[6];
char actDatum2[9];

int val;

void setup() {
  Serial.begin(9600);

  pinMode(7, INPUT);
  pinMode(13, OUTPUT);
 
  clock.begin();
  clock.setDateTime(__DATE__, __TIME__);
 
  m.init();
  m.setIntensity(15);

}

void loop() {
  if(Serial.available()){
    val = Serial.read();
  }
  if(val == 1){
    digitalWrite(13, HIGH);
  }else{
    digitalWrite(13, LOW);
  }
  now = clock.getDateTime();
  if(digitalRead(7)){
    m.clear();
    delay(300);
    if(mode == 0){
      mode = 1;
      for(int i = 0; i < 8; i++){
        m.setDot(23, i, 0);
      }
    }else if(mode == 1){
      mode = 2;
    }else if(mode == 2){
      mode = 0;
    }else if(mode == 3){
      mode = 0;
    }
  }
   
    if(mode == 0){
      createTime(false);
      printString(actTime);
      rotateDots(50);
    }else if(mode == 1){
      createDate();
      printString(actDatum);
    }else if(mode == 2){
      createExtendedDate();
      printStringWithShift(actDatum2, 200);
    }
   
    double test = round(now.second/7.5);
    if(test < 1 && mode == 0){
      for(int i = 0; i < 8; i++){
        m.setDot(23, i, 0);
      }
    }else if(mode == 0){
      for(int i = 0; i <= test; i++){
        m.setDot(23, i, 1);
      }
    }

}


void createTime(bool dots) {
  actTime[0] = (now.hour / 10) + '0';
  actTime[1] = (now.hour % 10) + '0';
  if(dots){
   actTime[2] = ':';
  }else{
   actTime[2] = ' ';
  }
  actTime[3] = (now.minute / 10) + '0';
  actTime[4] = (now.minute % 10) + '0';
  actTime[5] = 0;
}
void createDate() {
  actDatum[0] = (now.day / 10) + '0';
  actDatum[1] = (now.day % 10) + '0';
  actDatum[2] = '.';
  actDatum[3] = (now.month / 10) + '0';
  actDatum[4] = (now.month % 10) + '0';
  actDatum[5] = 0;
}
void createExtendedDate() {
  actDatum2[0] = (now.day / 10) + '0';
  actDatum2[1] = (now.day % 10) + '0';
  actDatum2[2] = '.';
  actDatum2[3] = (now.month / 10) + '0';
  actDatum2[4] = (now.month % 10) + '0';
  actDatum2[5] = '.';
  actDatum2[6] = '2';
  actDatum2[7] = '0';
  actDatum2[8] = '1';
  actDatum2[9] = '9';
  actDatum2[10] = ' ';
  actDatum2[11] = ' ';
  actDatum2[12] = 0;
}
bool milliDelay(int inter, int timeInt){
  if(millis() - timeInt >= inter){
   
    return true;
  }
}
void blinkDots(int speed){
  if(millis()-prevMillis >= 1000){
    prevMillis = millis();/*
    m.setDot(10, 3, i);
    m.setDot(10, 2, i);
    m.setDot(11, 2, i);
    m.setDot(11, 3, i);

    m.setDot(11, 5, i);
    m.setDot(11, 6, i);
    m.setDot(11, 5, i);
    m.setDot(11, 6, i);*/
  }
}
void rotateDots(int speed){ // THIS IS THE SECOND PROBLEM I DECLARED IN THE POST
                                        // this is NOT working like this, just the last attempt from me

    if (milliDelay(speed, time1)) {
      time1 = millis();
        m.setDot(10, 3, 1);
    }
    if (milliDelay(speed, time2)) {
       time2 = millis();
        m.setDot(10, 2, 1);
    }
    if (milliDelay(speed, time3)) {
      time3 = millis();
        m.setDot(11, 2, 1);
    }
    if (milliDelay(speed, time4)) {
       time4 = millis();
        m.setDot(11, 3, 1);
    }
   
    if (milliDelay(speed, time5)) {
      m.setDot(11, 5, 1);
      time5 = millis();
    }
    if (milliDelay(speed, time6)) {
      m.setDot(11, 6, 1);
      time6 = millis();
    }
    if (milliDelay(speed, time7)) {
      m.setDot(10, 6, 1);
      time7 = millis();
    }
    if (milliDelay(speed, time8)) {
      m.setDot(10, 5, 1);
      time8 = millis();
    }
    if (milliDelay(speed, time1)) {
      time1 = millis();
        m.setDot(10, 3, 1);
    }
    if (milliDelay(speed, time2)) {
       time2 = millis();
        m.setDot(10, 2, 1);
    }
    if (milliDelay(speed, time3)) {
      time3 = millis();
        m.setDot(11, 2, 1);
    }
    if (milliDelay(speed, time4)) {
       time4 = millis();
        m.setDot(11, 3, 1);
    }
   
    if (milliDelay(speed, time5)) {
      m.setDot(11, 5, 1);
      time5 = millis();
    }
    if (milliDelay(speed, time6)) {
      m.setDot(11, 6, 1);
      time6 = millis();
    }
    if (milliDelay(speed, time7)) {
      m.setDot(10, 6, 1);
      time7 = millis();
    }
    if (milliDelay(speed, time8)) {
      m.setDot(10, 5, 1);
      time8 = millis();
    }
}
void printCharWithShift(char c, int shift_speed){
  if (c < 32) return;
  c -= 32;
  memcpy_P(buffer, CH + 7*c, 7);
  m.writeSprite(32, 0, buffer);
  m.setColumn(32 + buffer[0], 0);
  for (int i=0; i<buffer[0]+1; i++)
  {
        delay(shift_speed);  // THIS IS WHAT I WANNA GET OUT AND REPLACE WITH MILLIS
        m.shiftLeft(false, false);
  }
}
/**********************************************************************************************************/
void printStringWithShift(char* s, int shift_speed){
  while (*s != 0){
    printCharWithShift(*s, shift_speed);
    s++;
  }
}
/**********************************************************************************************************/
void printString(char* s)
{
  int col = 0;
  while (*s != 0)
  {
    if (*s < 32) continue;
    char c = *s - 32;
    memcpy_P(buffer, CH + 7*c, 7);
    m.writeSprite(col, 0, buffer);
    m.setColumn(col + buffer[0], 0);
    col += buffer[0] + 1;
    s++;
  }
}

sendHelpPls

ADDITION TO POST (TOO MANY CHARACTERS)

Code: [Select]
const byte PROGMEM CH[] = {
2, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
1, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // '
3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
4, 8, B01000010, B01111111, B01000000, B01000000, B00000000, // 1
4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
2, 8, B01101100, B01101100, B01110000, B01110000, B00000000, // :
2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
4, 8, B01111110, B01001000, B01001000, B00110000, B00000000, // b
4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
3, 8, B00001000, B01111100, B00001010, B00000000, B00000000, // f
4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
};

Paul__B

You need to read the pushbutton every time you use delay().
***

Wow!

Sorry, I cannot deal with your code - too confused.  I know nothing about "MAXMATRIX" but examples using delay() are ipso facto useless.  I use the Parola codes.  I'm letting this one through to the keeper!

marco_c

The Parola library (link in my signature block below) has an example showing a clock that you could use as a starting point.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

sendHelpPls

#4
May 10, 2019, 01:14 pm Last Edit: May 10, 2019, 01:23 pm by sendHelpPls
Hey thanks for ur replies and jes my code is confusing,
I tried the Parola Lib but because i dont use the mx7219 4x module where these are already connected to each other horizontaly, i could not get the Parola lib to work (the text was rotated by 90° and was scrolling from up to down on the right sided mx panel into the top of the middle one and so on...)

if you could tell me how to set the orientation of the panels in the parola lib that would be useful

in love
ur designated ugly fat friend

marco_c

The  4 connected modules make no difference, they are still 4 independent modules.

You have a few options to work it out yourself:
0. Read the code and realize that you need to specify the hardware type.
1. Read the MD_MAX72xx documentation that says how to adapt for different hardware.
2. Do the same from the Parola library documentation.
3. Follow the links from the Parola library documentation to a blog that explains same.
4. Learn how to use Google and see the many articles on how to do this (some wrong) but lots out there.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

sendHelpPls

ok guys i made it using the parola lib,
this lib that i used was just total crap :(

thanks for ur replies

Go Up