0

EDIT2: Well, this is the "new" code and it just displays random dots on the matrices:

#include "RTClib.h"

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 16
#define NUM_ZONES 4

#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

RTC_DS3231 rtc;
#define SPEED_TIME  25
#define PAUSE_TIME  1000

uint8_t lastUpdateMin = 0;
uint8_t lastUpdateHour = 0;

// Global variable
const char  *pc[NUM_ZONES] =
{
  "TIME",
  "ROOM", //0
  "SUBJECT", //1
  "GRADE",//2
  };

void setup(void)
{

  P.begin();
    if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

 if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
//     If the RTC have lost power it will set the RTC to the date & time this sketch was compiled in the following line
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 }

 P.begin(4);
  P.setZone(0, 0, 3); // Modules 0-3 in zone 0
  P.setZone(1, 4, 7); // Modules 4-7 in zone 1
  P.setZone(2, 8, 11); // Modules 8-11 in zone 2
  P.setZone(3, 12, 15); // Modules 12-15 in zone 3
}

void loop(void)
{

 DateTime now = rtc.now();
 if(lastUpdateMin != now.minute()){  // change every minute
     lastUpdateMin = now.minute();
 char buffer[] = "hh:mm";  // hours and minutes
P.displayZoneText(0,now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);

    if(lastUpdateHour != now.hour()){     // change every hour
     lastUpdateHour = now.hour();
   P.displayZoneText(1, pc[1], PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT);
   P.displayZoneText(2, pc[2], PA_LEFT, 0, 0, PA_PRINT, PA_NO_EFFECT);  // display
   P.displayZoneText(3, pc[3], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
   }
  }
   P.displayAnimate();
}

If I do just this:

void loop(void)
{

 DateTime now = rtc.now();
 if(lastUpdateMin != now.minute()){  // change every minute
     lastUpdateMin = now.minute();
 char buffer[] = "hh:mm";  // hours and minutes
P.displayZoneText(0,now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
 }
     if(lastUpdateHour != now.hour()){     // change every hour
     lastUpdateHour = now.hour();

     }

   P.displayAnimate();
}

it displays the hour:minutes. the problem is it doesn't display the time and the other text at the same time

EDIT: If I execute this code below it will display text on the first row, but my question will be how do I manage to display simultaneously the hour:minutes from the clock and some text of my choice?

void setup(void)
{

  P.begin();
    if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

 if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
//     If the RTC have lost power it will set the RTC to the date & time this sketch was compiled in the following line
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 }

 P.begin(4);
  P.setZone(0, 0, 3); // Modules 0-3 in zone 0
  P.setZone(1, 4, 7); // Modules 4-7 in zone 1
  P.setZone(2, 8, 11); // Modules 8-11 in zone 2
  P.setZone(3, 12, 15); // Modules 12-15 in zone 3

for (uint8_t i=0; i<NUM_ZONES; i++)
    P.displayZoneText(0, pc[0], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);

}

void loop(void)
{

 DateTime now = rtc.now();
 char buffer[] = "hh:mm";  // hours and minutes

// P.displayZoneText(0,now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);  // display
//if(now.hour()==12){
//  P.displayZoneText(0, pc[0], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
//}  
//else{
 // P.displayZoneText(1, pc[1], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);  // display
//}
   P.displayAnimate();
}

I have multiple FC-16 modules based on MAX7219 led matrices and I want to use them and a real time clock, DS3231, to build a classroom timetable.

I want the led modules to operate on the concept of zones. I want to create a zone for each row of text (a zone is a contiguous block of modules forming a kind of sub-display) as I did here: P.begin(4); // We will have 4 zones P.setZone(0, 0, 3); // Modules 0-3 in zone 0 P.setZone(1, 4, 7); // Modules 4-7 in zone 1 P.setZone(2, 8, 11); // Modules 8-11 in zone 2 P.setZone(3, 12, 15); // Modules 12-15 in zone 3

I want this in order to be able to change the text in a row without modifying other rows.

Then, I need to use the hour and minutes from the DS3231 clock module and to display it on the first row of the display and on the other 3 rows I need to display the number of the room, the subject and the class.

const char  *pc[NUM_ZONES] =
{
  "ROOM",
  "SUBJECT",
  "CLASS",};

And when the hour on the first row changes, the text from the other 3 rows should change simultaneously.It's a pretty simple concept but I can't seem to know how to manage this. This is all the code I gathered up until now:

#include "RTClib.h"

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 16
#define NUM_ZONES 4

#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
RTC_DS3231 rtc;
#define SPEED_TIME  25
#define PAUSE_TIME  1000

// Global variables
uint8_t  curText;
const char  *pc[NUM_ZONES] =
{
  "ROOM",
  "SUBJECT",
  "CLASS",

};

void setup(void)
{

  P.begin();
    if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

 if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
//     If the RTC have lost power it will set the RTC to the date & time this sketch was compiled in the following line
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 }

 P.begin(4);
  P.setZone(0, 0, 3); // Modules 0-3 in zone 0
  P.setZone(1, 4, 7); // Modules 4-7 in zone 1
  P.setZone(2, 8, 11); // Modules 8-11 in zone 2
  P.setZone(3, 12, 15); // Modules 12-15 in zone 3

}

void loop(void)
{

 DateTime now = rtc.now();
 char buffer[] = "hh:mm";  // hours and minutes

   for (uint8_t i=0; i<NUM_ZONES; i++)
    P.displayZoneText(i-1, now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);

P.displayAnimate();
}

I dont't know how to display the hour:minutes and my text simultaneously so that I can do the rest then:

{

 DateTime now = rtc.now();
 char buffer[] = "hh:mm";  // hours and minutes

   for (uint8_t i=0; i<NUM_ZONES; i++)
    P.displayZoneText(i-3, now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT); //here I want to display the hour:minutes on the first row

P.displayAnimate();
}```
  • edited just now – Rehoboam May 15 at 15:08
  • I know how to display text in all 4 zones. I don't know how to display the real time from the clock module and some other text simultaneously – Rehoboam May 15 at 16:38
  • I know how to do that too – Rehoboam May 15 at 17:07
  • What is the Parola library? Where can your readers find this library? What kind of display does it work with? Briefly, what does it do for you? You should provide all of that information in your question. – Duncan C May 15 at 17:11
  • Parola is mainly used to format text on led matrix displays. My FC16 led modules are based on MAX7219 led matrices. I can't really figure out how to display the time properly and a message simultaneously – Rehoboam May 15 at 18:05
1

Your first problem is the definition of the text array:

const char  *pc[NUM_ZONES] =
{ "TIME",      // This will be replaced by real time its only for logic of rows here
  "ROOM",
  "SUBJECT",
  "CLASS"
};

then we need a timer, as you only show minutes we only have to change time in that interval to prevent flicker and other unwanted effects and hour for changing texts lateron:

uint8_t lastUpdateMin = 0;
uint8_t lastUpdateHour = 0;

Then the loop looks like

void loop() {
   DateTime now = rtc.now();
   if(lastUpdateMin != now.minute()){  // change every minute
     lastUpdateMin = now.minute();
     char buffer[] = "hh:mm";  // hours and minutes
     P.displayZoneText(0, now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT); // 1st row
    }
  if(lastUpdateHour != now.hour()){     // change every hour
     lastUpdateHour = now.hour();
     P.displayZoneText(1, pc[1], PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT);  // 2nd row
     P.displayZoneText(2, pc[2], PA_LEFT, 0, 0, PA_PRINT, PA_NO_EFFECT);   // 3rd row
     P.displayZoneText(3, pc[3], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT); // 4th row
    }
P.displayAnimate();
}

Things to do - define a two dimensional char table with all the texts needed for the different hours

#define NUM_LECTUREHOURS 7       // seven hour lectures
const char *pc[NUM_LECTUREHOURS][NUM_ZONES] = {
  { "TIME", "ROOM_0", "SUBJECT_0", "CLASS_0"},
  { "TIME", "ROOM_1", "SUBJECT_1", "CLASS_1"},
  { "TIME", "ROOM_2", "SUBJECT_2", "CLASS_2"},
  ...
  { "TIME", "ROOM_Last", "SUBJECT_Last", "CLASS_Last"}  // _Last in this example = 6
};

and display with a variable based on the hour so if your classes start at 9:00 you would use

uint8_t lectureHour= now.hour() - 9; // as arrays start with 0

and your different texts would be called like

  P.displayZoneText(1, pc[lectureHour][1], PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT); // 2nd row

If your char array gets to large - depending on the texts - you will have to use PROGMEM which is an issue on its own. Hope this gets you started

EDIT If you want to change every two hours you do

if(lastUpdateHour != now.hour() && lastUpdateHour +1 != now.hour() ){ // change every two hours

or shorter for a variable timespan (e.g. every three hours)

 if( now.hour() - lastUpdateHour > 3 ){     // change every three hours
| improve this answer | |
  • I did everything you showed me until the char table and it isn't working. It's not displaying anything. And when I build the char table it says "conflicting declaration 'const char* pc [7][4[' " – Rehoboam May 16 at 8:20
  • Please start with the simple example and test, do not go for the full solution before you make the simple work. And edit your question and show the "new" code – Codebreaker007 May 16 at 8:46
  • just did that . – Rehoboam May 16 at 10:10
  • I guess you just start your ESP so hour returned = 0 so either wait one hour (just kidding) or set the initial hour to 99 and use my original loop as in your program is an errorinbrackets! – Codebreaker007 May 16 at 12:33
  • god bless! and if I want to change the text every 2 hours? – Rehoboam May 16 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.