LED Matrix Anzeige durch Taster wechseln

Hallo liebe Forumsgemeinde,

Ich als "Ober"-Neuling hätte da mal eine Frage. (d.h. hab gar keine Erfahrung)

Die LED Matrix zeigt derzeit die Uhrzeit an, die ich von einer DS3231 erhalte!
Jetzt würde ich gerne das Sie mir per Tasterdruck, für ca. 5-10s, das Datum anzeigt.

Ich komme da einfach nicht weiter.
Ich weiss einfach nicht wie es anstellen soll!
(Hatte kurze Unterstützung, die ist aber selten zu erreichem)

Arduino UNO Klon + 4x 8x8 LED Matrix + DS 3231 + einfachen Taster


// Use the MD_MAX72XX library to scroll text on the display
//
// Demonstrates the use of the callback function to control what
// is scrolled on the display text.
//
// User can enter text on the serial monitor and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.

#include <MD_MAX72xx.h>
#include <SPI.h>
#include <DS3231.h>
#include <Wire.h>

DS3231 clock_rtc;
bool h12Flag;
bool pmFlag;
bool century = false;
const int buttonPin = 2; // GND -> Taster -> Pin2(Digital)
int buttonState = 0;

#define PRINT_CALLBACK  0

#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }

// 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 4

#define CLK_PIN   13  // or SCK
#define DATA_PIN  11  // or MOSI
#define CS_PIN    10  // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

#define CHAR_SPACING  1 // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE  75
char curMessage[BUF_SIZE];
bool newMessageAvailable = true;

void readSerial(void)
{
  static uint8_t  putIndex = 0;

  while (Serial.available())
  {
    curMessage[putIndex] = (char)Serial.read();
    if ((curMessage[putIndex] == '\n') || (putIndex >= BUF_SIZE-3))  // end of message character or full buffer
    {
      // put in a message separator and end the string
      curMessage[putIndex] = '\0';
      // restart the index for next filling spree and flag we have a message waiting
      putIndex = 0;
      newMessageAvailable = true;
    }
    else
      // Just save the next char in next location
      curMessage[putIndex++];
  }
}

void printText(uint8_t modStart, uint8_t modEnd, char *pMsg)
// Print the text string to the LED matrix modules specified.
// Message area is padded with blank columns after printing.
{
  uint8_t   state = 0;
  uint8_t   curLen;
  uint16_t  showLen;
  uint8_t   cBuf[8];
  int16_t   col = ((modEnd + 1) * COL_SIZE) - 1;

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);

  do     // finite state machine to print the characters in the space available
  {
    switch(state)
    {
      case 0: // Load the next character from the font table
        // if we reached end of message, reset the message pointer
        if (*pMsg == '\0')
        {
          showLen = col - (modEnd * COL_SIZE);  // padding characters
          state = 2;
          break;
        }

        // retrieve the next character form the font file
        showLen = mx.getChar(*pMsg++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
        curLen = 0;
        state++;
        // !! deliberately fall through to next state to start displaying

      case 1: // display the next part of the character
        mx.setColumn(col--, cBuf[curLen++]);

        // done with font character, now display the space between chars
        if (curLen == showLen)
        {
          showLen = CHAR_SPACING;
          state = 2;
        }
        break;

      case 2: // initialize state for displaying empty columns
        curLen = 0;
        state++;
        // fall through

      case 3: // display inter-character spacing or end of message padding (blank columns)
        mx.setColumn(col--, 0);
        curLen++;
        if (curLen == showLen)
          state = 0;
        break;

      default:
        col = -1;   // this definitely ends the do loop
    }
  } while (col >= (modStart * COL_SIZE));

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}
void intensity() {
 mx.control(MD_MAX72XX::INTENSITY, 2);
}


//Uhrzeit-Anzeige
void setmessage_clock()
{
  
  byte hour;
  hour = clock_rtc.getHour(h12Flag, pmFlag);
  curMessage[0] = 32;
  curMessage[1] = (hour/10)+48;
  curMessage[2] = (hour%10)+48;
  curMessage[3] = 58;
  
  byte minute;
  minute = clock_rtc.getMinute();
  curMessage[4] = (minute/10)+48;
  curMessage[5] = (minute%10)+48;
  //curMessage[5] = 58;
    
  /*byte second;
  second = clock_rtc.getSecond();
  //curMessage[3] = (second/10);
  curMessage[3] = (second%10)+58;  
  //curMessage[8] = 95;
  */
}

// Datum-Anzeige
 void setmessage_date()
{

  byte day;
  day = clock_rtc.getDate();
  curMessage[0] = (day/10)+48;
  curMessage[1] = (day%10)+48;

  byte month;
  month = clock_rtc.getMonth(century);
  curMessage[2] = 58;
  curMessage[3] = (month/10)+48;
  curMessage[4] = (month%10)+48;

  byte year;
  year = clock_rtc.getYear();
  curMessage[5] = 58;
  curMessage[6] = (year/10)+48;
  curMessage[7] = (year%10)+48;

     
  }
  
void setup()
{
  mx.begin();
  strcpy(curMessage, " ");

  Serial.begin(57600);
  Serial.print("\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline");

  Wire.begin();

  pinMode(buttonPin, INPUT_PULLUP);
}


void loop()
{
  readSerial();
  printText(0, MAX_DEVICES-1, curMessage);
  intensity();
  setmessage_clock();
  //setmessage_date();
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW)
  {
    Serial.print("  ");
    Serial.print(clock_rtc.getDate(), DEC);
    Serial.print(".");
    Serial.print(clock_rtc.getMonth(century), DEC);
    Serial.print(".");
    Serial.print(clock_rtc.getYear(), DEC);
    Serial.print("     ");
    Serial.print(clock_rtc.getTemperature(), 2);
    mx.control(MD_MAX72XX::INTENSITY, 9);
    delay (5000);
    
  }
}

Ich hoffe mir kann da mal einer helfen...

Und ich bitte drum alles zu bemängeln was nicht wirklich sinnvoll ist, ich muss es ja wissen,
um es besser machen zu können.

MfG Hirschi

Alles was define ist, gehört wohl als const gemacht.

Ne Idee für die Anzeige:


void loop()
{
  static unsigned long startTime = 0;
  const unsigned long dateDisplay = 5000;
  static bool isDate = false;
  readSerial();
  printText(0, MAX_DEVICES - 1, curMessage);
  intensity();
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW && isDate == false)
  {
    Serial.print("  ");
    Serial.print(clock_rtc.getDate(), DEC);
    Serial.print(".");
    Serial.print(clock_rtc.getMonth(century), DEC);
    Serial.print(".");
    Serial.print(clock_rtc.getYear(), DEC);
    Serial.print("     ");
    Serial.print(clock_rtc.getTemperature(), 2);
    mx.control(MD_MAX72XX::INTENSITY, 9);
    startTime = millis();
    isDate = true;
  }
  if (isDate == true)
  {
    setmessage_date()
  }
  else
  {
    setmessage_clock();
  }
  if (millis() - startTime > dateDisplay)
  {
    isDate == false;
  }
}

Wobei das mit der intensity dann nicht mehr zurück kommt und da noch was rein gehört.

@my_xy_projekt

Das Datum zeigt er auf jedenfall schonmal an, coole Sache.
Aber, er springt nicht zur Uhrzeit zurück, und die Helligkeit ändert sich gar nicht...
Trotzdem schon mal danke, vlt. komme ich auch noch alleine weiter.
Probieren geht über studieren wa, xD...

Könntest du mir die ersten 3 Sachen in Setup erklären?

Aehm ich hab grad gesehen, das nach setmessage_date() noch ein ; fehlt.
Das müsste doch eigentlich gar nicht kompiliert haben ;(

Das mit der Helligkeit habe ich erkärt.
Wenn die einmal gesetzt ist, kommt die nicht mehr zurück.

Und dann mach mal aus:

ein isDate = false
Und schon kommt die Anzeige zurück.
Ich zitter auf dem = aus physischen Gründen.

Jupp, das klappt jetzt mit dem zurück springen.
Jetze, müsste man mal das Display löschen und neu laden beim wechsel zur Uhrzeit, da er mir
noch ne 2 anzeigt vom Datum...
würde da nicht mx.clear() funktionieren? Wie gesagt bin da Laie!!!!

Die Helligkeitsänderung hat ja vorher funktioniert, ich brauche die aber nicht.
War nur eine Spielerei um zu schauen was man alles so machen kann.

Kannste versuchen - in der Stelle wo isDate = false gesetzt wird, noch eine neue Zeile rein - dann wird gelöscht und oben wieder gesetzt.

Sollte gehen

Find ich toll das einem hier so geholfen wird, besten Dank schonmal...

Also, die Hellikeitsänderung funzt wenn man Sie bei

if (isDate == true)  
  {
    setmessage_date();
    mx.control(MD_MAX72XX::INTENSITY, 2);
  }

einfügt...

mx.clear() funzt auch nicht, da fangen die LEDs an zu flackern xD

Doch, das funktioniert schon
Aber Du musst natürlich vermeiden, das das dauernd aufgerufen wird...

  if (millis() - startTime > dateDisplay && isDate==true)
  {
    isDate = false;
    mx.clear();
  }

Bedenke! ich mach das blind. Weder Hardware noch libs etc...

Alles kein Problem, wie soll das denn auch funktionieren.
Man kann ja nicht alles zu Hause haben, was die halbwilden in Internet alles basteln wollen.

https://majicdesigns.github.io/MD_MAX72XX/

Das ist die Lib für die Matrix, die ich benutze...

Das flackern ist weg, aber die Zahl ist immer noch da.
Hat nicht den richtigen Effekt...

https://majicdesigns.github.io/MD_MAX72XX/class_m_d___m_a_x72_x_x.html#a3f91498bfc0023f67d4bf1284ca70317

Oder muss man dieses update() benutzen?

Edit:

Hab mal das Jahr weggenommen, und jetzt Zeigt er mir beim Datum die Minute mit an.

Irgenwie muss es doch möglich sein, die Matrix beim wechseln löschen oder neu starten zu können.

Oder auch nicht xD

Ich hab in den xamples mal geschaut...

Da ist die Sequenz für ein neues Display:
mx.clear();
mx.control(MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);

Ich bin da aber raus - Du wolltest das tauschen der Displays - das hab ich gemacht :slight_smile:

Alles klar Kollege, trotzdem vielen Dank...

Hast mich schon ein Stück weitergebracht...

Edit:

Hab mir erstmal so geholfen das ich Anfang des Datums ein leerzeichen gesetzt habe und zum Ende auch.

Durch das eintragen mx.clear() und dem anderen kam es wieder zum flackern.

Das Jahr hätte ja eh nicht ganz gepasst.

So sieht es jetzt aus vom Code....

[code]

// Use the MD_MAX72XX library to scroll text on the display
//
// Demonstrates the use of the callback function to control what
// is scrolled on the display text.
//
// User can enter text on the serial monitor and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.

#include <MD_MAX72xx.h>
#include <SPI.h>
#include <DS3231.h>
#include <Wire.h>

DS3231 clock_rtc;
bool h12Flag;
bool pmFlag;
bool century = false;
const int buttonPin = 2; // GND -> Taster -> Pin2(Digital)
int buttonState = 0;

#define PRINT_CALLBACK  0

#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }

// 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 4

#define CLK_PIN   13  // or SCK
#define DATA_PIN  11  // or MOSI
#define CS_PIN    10  // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

#define CHAR_SPACING  1 // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE  75
char curMessage[BUF_SIZE];
bool newMessageAvailable = true;

void readSerial(void)
{
  static uint8_t  putIndex = 0;

  while (Serial.available())
  {
    curMessage[putIndex] = (char)Serial.read();
    if ((curMessage[putIndex] == '\n') || (putIndex >= BUF_SIZE-3))  // end of message character or full buffer
    {
      // put in a message separator and end the string
      curMessage[putIndex] = '\0';
      // restart the index for next filling spree and flag we have a message waiting
      putIndex = 0;
      newMessageAvailable = true;
    }
    else
      // Just save the next char in next location
      curMessage[putIndex++];
  }
}

void printText(uint8_t modStart, uint8_t modEnd, char *pMsg)
// Print the text string to the LED matrix modules specified.
// Message area is padded with blank columns after printing.
{
  uint8_t   state = 0;
  uint8_t   curLen;
  uint16_t  showLen;
  uint8_t   cBuf[8];
  int16_t   col = ((modEnd + 1) * COL_SIZE) - 1;

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);

  do     // finite state machine to print the characters in the space available
  {
    switch(state)
    {
      case 0: // Load the next character from the font table
        // if we reached end of message, reset the message pointer
        if (*pMsg == '\0')
        {
          showLen = col - (modEnd * COL_SIZE);  // padding characters
          state = 2;
          break;
        }

        // retrieve the next character form the font file
        showLen = mx.getChar(*pMsg++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
        curLen = 0;
        state++;
        // !! deliberately fall through to next state to start displaying

      case 1: // display the next part of the character
        mx.setColumn(col--, cBuf[curLen++]);

        // done with font character, now display the space between chars
        if (curLen == showLen)
        {
          showLen = CHAR_SPACING;
          state = 2;
        }
        break;

      case 2: // initialize state for displaying empty columns
        curLen = 0;
        state++;
        // fall through

      case 3: // display inter-character spacing or end of message padding (blank columns)
        mx.setColumn(col--, 0);
        curLen++;
        if (curLen == showLen)
          state = 0;
        break;

      default:
        col = -1;   // this definitely ends the do loop
    }
  } while (col >= (modStart * COL_SIZE));

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}
void intensity() {
 mx.control(MD_MAX72XX::INTENSITY, 2);
}


//Uhrzeit-Anzeige
void setmessage_clock()
{
  
  byte hour;
  hour = clock_rtc.getHour(h12Flag, pmFlag);
  curMessage[0] = 32;
  curMessage[1] = (hour/10)+48;
  curMessage[2] = (hour%10)+48;
  curMessage[3] = 58;
  
  byte minute;
  minute = clock_rtc.getMinute();
  curMessage[4] = (minute/10)+48;
  curMessage[5] = (minute%10)+48;
  //curMessage[5] = 58;
    
  /*byte second;
  second = clock_rtc.getSecond();
  //curMessage[3] = (second/10);
  curMessage[3] = (second%10)+58;  
  //curMessage[8] = 95;
  */
}

// Datum-Anzeige
 void setmessage_date()
{

  byte day;
  day = clock_rtc.getDate();
  curMessage[0] = 32;
  curMessage[1] = (day/10)+48;
  curMessage[2] = (day%10)+48;

  byte month;
  month = clock_rtc.getMonth(century);
  curMessage[3] = 46;
  curMessage[4] = (month/10)+48;
  curMessage[5] = (month%10)+48;
  curMessage[6] = 32;
  /*byte year;
  year = clock_rtc.getYear();
  curMessage[5] = 58;
  curMessage[6] = (year/10)+48;
  curMessage[7] = (year%10)+48;*/

     
  }
  
void setup()
{
  mx.begin();
  strcpy(curMessage, " ");

  Serial.begin(57600);
  Serial.print("\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline");

  Wire.begin();

  pinMode(buttonPin, INPUT_PULLUP);
}


void loop()
{
  static unsigned long startTime = 0;
  const unsigned long dateDisplay = 5000;
  static bool isDate = false;
  readSerial();
  printText(0, MAX_DEVICES - 1, curMessage);
  intensity();
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW && isDate == false)
  {
    Serial.print("  ");
    Serial.print(clock_rtc.getDate(), DEC);
    Serial.print(".");
    Serial.print(clock_rtc.getMonth(century), DEC);
    Serial.print(".");
    Serial.print(clock_rtc.getYear(), DEC);
    Serial.print("     ");
    Serial.println(clock_rtc.getTemperature(), 2);
    startTime = millis();
    isDate = true;
  }
  if (isDate == true)  
  {
    setmessage_date();
  }
  else
  {
    setmessage_clock();
  }
  if (millis() - startTime > dateDisplay && isDate==true)
  {
    isDate = false;
  }
}
[/code]

Ein MakeUp überdeckt die Unreinheit und behebt diese nicht.

Schau, was Dir die lib bietet - und schau, wann Du was auszuführen hast.
Zusammenkopieren hilft nicht.

Ja das ist vollkommen richtig, habe jetzt die Leerzeichen wieder rausgenommen.

Aber es funktioiniert jetzt, es liegt denke ich daran das wir Die Zeichen an den gleichen "selben"
Stellen "überschreiben". Ansonsten wäre die Anzeige ja nicht mittig geworden.

Ist das so ok, oder müsste das dann doch noch überarbeitet werden?

@my_xy_projekt

Ich muss jetzt mal nochmal nachhaken...

Ich habe den Code denn du überarbeitest hast für einen weiteren Taster erweitert.

void loop()
{
  static unsigned long startTime = 0;
  const unsigned long dateDisplay = 5000;
  static bool isDate = false;
  static bool isTemp = false;
  readSerial();
  printText(0, MAX_DEVICES - 1, curMessage);
  intensity();
  buttonState1 = digitalRead(TasterDate);
  buttonState2 = digitalRead(TasterTemp);
  if (buttonState1 == LOW && isDate == false)
  {
    startTime = millis();
    isDate = true;
  }
  if (isDate == true)  
  {
    setmessage_date();
  }
  else
  {
    setmessage_clock();
  }
  if (millis() - startTime > dateDisplay && isDate==true)
  {
    isDate = false;
  }  
  if (buttonState2 == LOW && isTemp == false)
  {
    startTime = millis();
    isTemp = true;
  }
  if (isTemp == true)
  {
    setmessage_temp();
  }
  else
  {
    setmessage_clock();
  }
  if (millis() - startTime > dateDisplay && isTemp==true)
  {
    isTemp = false;    
  }
}

Das funktioniert aber nicht so wie ich es dachte, stimmt das was mit der Reihenfolge nicht oder passt das mit den ganzen if nicht zusammen?

Mfg Hirschi

:slight_smile: So und ich stehe jetzt wie eine Kuh vor einem neuen Tor und frage mich.....
.... was hat er sich gedacht.
Bedenke: Du hast das auf dem Tisch. Und Du hast Gedanken.
Beides habe ich nicht.

Mach bitte wenigstens einen Kommentar in den Code, was Du an den entsprechenden Stellen erwartest.
Dann schreib kurz auf, was Du tatsächlich bekommst.
Es wäre sinnvoll, das als Gesamtpaket und nicht nur als Schnipsel zu posten. Ich sammel mir das nicht zusammen; Das es dann vollständig ist, dürfte unwahrscheinlich sein und den Rest müsste ich raten - habe ich grad gemacht und ist für zwei Zahlen in fast 400 Postst ausgeartet....

OK... :crazy_face:

Hier der Code

[code]

// Use the MD_MAX72XX library to scroll text on the display
//
// Demonstrates the use of the callback function to control what
// is scrolled on the display text.
//
// User can enter text on the serial monitor and this will display as a
// scrolling message on the display.
// Speed for the display is controlled by a pot on SPEED_IN analog in.

#include <MD_MAX72xx.h>
#include <SPI.h>
#include <DS3231.h>
#include <Wire.h>

DS3231 clock_rtc;
bool h12Flag;
bool pmFlag;
bool century = false;
const int TasterDate = 2; // GND -> Taster -> Pin2(Digital) Datum
const int TasterTemp = 4; // GND -> Taster -> Pin4(Digital) Temperatur
int buttonState1 = 0;
int buttonState2 = 0;

#define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); }

// 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 4

#define CLK_PIN   13  // or SCK
#define DATA_PIN  11  // or MOSI
#define CS_PIN    10  // or SS

// SPI hardware interface
MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary pins
//MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

#define CHAR_SPACING  1 // pixels between characters

// Global message buffers shared by Serial and Scrolling functions
#define BUF_SIZE  75
char curMessage[BUF_SIZE];
bool newMessageAvailable = true;

void readSerial(void)
{
  static uint8_t  putIndex = 0;

  while (Serial.available())
  {
    curMessage[putIndex] = (char)Serial.read();
    if ((curMessage[putIndex] == '\n') || (putIndex >= BUF_SIZE-3))  // end of message character or full buffer
    {
      // put in a message separator and end the string
      curMessage[putIndex] = '\0';
      // restart the index for next filling spree and flag we have a message waiting
      putIndex = 0;
      newMessageAvailable = true;
    }
    else
      // Just save the next char in next location
      curMessage[putIndex++];
  }
}

void printText(uint8_t modStart, uint8_t modEnd, char *pMsg)
// Print the text string to the LED matrix modules specified.
// Message area is padded with blank columns after printing.
{
  uint8_t   state = 0;
  uint8_t   curLen;
  uint16_t  showLen;
  uint8_t   cBuf[8];
  int16_t   col = ((modEnd + 1) * COL_SIZE) - 1;

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::OFF);

  do     // finite state machine to print the characters in the space available
  {
    switch(state)
    {
      case 0: // Load the next character from the font table
        // if we reached end of message, reset the message pointer
        if (*pMsg == '\0')
        {
          showLen = col - (modEnd * COL_SIZE);  // padding characters
          state = 2;
          break;
        }

        // retrieve the next character form the font file
        showLen = mx.getChar(*pMsg++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
        curLen = 0;
        state++;
        // !! deliberately fall through to next state to start displaying

      case 1: // display the next part of the character
        mx.setColumn(col--, cBuf[curLen++]);

        // done with font character, now display the space between chars
        if (curLen == showLen)
        {
          showLen = CHAR_SPACING;
          state = 2;
        }
        break;

      case 2: // initialize state for displaying empty columns
        curLen = 0;
        state++;
        // fall through

      case 3: // display inter-character spacing or end of message padding (blank columns)
        mx.setColumn(col--, 0);
        curLen++;
        if (curLen == showLen)
          state = 0;
        break;

      default:
        col = -1;   // this definitely ends the do loop
    }
  } while (col >= (modStart * COL_SIZE));

  mx.control(modStart, modEnd, MD_MAX72XX::UPDATE, MD_MAX72XX::ON);
}
void intensity() {
 mx.control(MD_MAX72XX::INTENSITY, 2);
}


//Uhrzeit-Anzeige
void setmessage_clock()
{
  
  byte hour;
  hour = clock_rtc.getHour(h12Flag, pmFlag);
  //curMessage[0] = 32;
  curMessage[1] = (hour/10)+48;
  curMessage[2] = (hour%10)+48;
  curMessage[3] = 58;
  
  byte minute;
  minute = clock_rtc.getMinute();
  curMessage[4] = (minute/10)+48;
  curMessage[5] = (minute%10)+48;
  //curMessage[5] = 58;
    
  /*byte second;
  second = clock_rtc.getSecond();
  //curMessage[3] = (second/10);
  curMessage[3] = (second%10)+58;  
  //curMessage[8] = 95;
  */
}

// Datum-Anzeige
 void setmessage_date()
{

  byte day;
  day = clock_rtc.getDate();
  //curMessage[0] = 32;
  curMessage[1] = (day/10)+48;
  curMessage[2] = (day%10)+48;

  byte month;
  month = clock_rtc.getMonth(century);
  curMessage[3] = 46;
  curMessage[4] = (month/10)+48;
  curMessage[5] = (month%10)+48;
  //curMessage[6] = 32;
  /*byte year;
  year = clock_rtc.getYear();
  curMessage[5] = 58;
  curMessage[6] = (year/10)+48;
  curMessage[7] = (year%10)+48;*/
  

     
  }
  // Temperatur-Anzeige

 void setmessage_temp()
 { 
  int temperature = (clock_rtc.getTemperature());
  //curMessage[0] = 46;
  curMessage[3] = ((temperature/10)%10)+48;
  curMessage[4] = (temperature%10)+48;
  curMessage[5] = 32;
  curMessage[6] = 67;
 }
 

void setup()
{
  mx.begin();
  strcpy(curMessage, "    ");

  Serial.begin(57600);
  Serial.print("\n[MD_MAX72XX Message Display]\nType a message for the scrolling display\nEnd message line with a newline");

  Wire.begin();

  pinMode(TasterDate, INPUT_PULLUP);
  pinMode(TasterTemp, INPUT_PULLUP);
}


void loop()
{
  static unsigned long startTime = 0;
  const unsigned long dateDisplay = 5000;
  static bool isDate = false;
  static bool isTemp = false;
  readSerial();
  printText(0, MAX_DEVICES - 1, curMessage);
  intensity();
  buttonState1 = digitalRead(TasterDate);
  buttonState2 = digitalRead(TasterTemp);
  if (buttonState1 == LOW && isDate == false)
  {
    startTime = millis();
    isDate = true;
  }
  if (isDate == true)  
  {
    setmessage_date();
  }
  else
  {
    setmessage_clock();
  }
  if (millis() - startTime > dateDisplay && isDate==true)
  {
    isDate = false;
  }  
  if (buttonState2 == LOW && isTemp == false)
  {
    startTime = millis();
    isTemp = true;
  }
  if (isTemp == true)
  {
    setmessage_temp();
  }
  else
  {
    setmessage_clock();
  }
  if (millis() - startTime > dateDisplay && isTemp==true)
  {
    isTemp = false;    
  }
}
[/code]

Ich möchte jetzt mit ButtonState2 (TasterTemp) mir die Temperatur anzeigen lassen und dann wieder nach ca. 5s wieder die Uhrzeit.

Wenn ich jetzt den Taster Date benutze passiert gar nichts und beim Taster Temp sieht es auf der Matrix aus als würde sich beide überschneiden.

Ein Versuch: - ungetestet und auch nicht kompiliert, ich komm mit der rtc auf die Schnelle nicht zurecht

void loop()
{
  static unsigned long startTime = 0;
  const unsigned long dateDisplay = 5000;
  static bool isDate = false;
  static bool isTemp = false;
  readSerial();
  printText(0, MAX_DEVICES - 1, curMessage);
  intensity();
  buttonState1 = digitalRead(TasterDate);
  buttonState2 = digitalRead(TasterTemp);
  if (buttonState1 == LOW && isDate == false)
  {
    startTime = millis();
    isDate = true;
    isTemp = false;
  }
  if (buttonState2 == LOW && isTemp == false)
  {
    startTime = millis();
    isTemp = true;
    isDate = false;
  }
  if (isDate == true)
  {
    setmessage_date();
  }
  else if (isTemp == true)
  {
    setmessage_temp();
  }
  else
  {
    setmessage_clock();
  }
  if ((millis() - startTime > dateDisplay) && (isDate == true || isTemp == true))
  {
    isDate = false;
    isTemp = false;
  }
}

@my_xy_projekt

man man, perfekt.... :grinning:

Das funktioniert wie ne eins.

Es hat also an der Zusammensetzung gelegen, sprich man hätte immer die andere Sache als "false" setzen müssen? So würde ich das jetzt verstehen.

Eine Frage hätte ich aber immer noch zur Matrix, es ist ja jetzt immer noch das Problem das dort immer noch Reste in der Anzeige bleiben.
ich hab mir die lib mal angeschaut, bin mir aber nicht sicher wie ich die Funktion einbringe soll

https://majicdesigns.github.io/MD_MAX72XX/class_m_d___m_a_x72_x_x.html#acff691690cb5848980f10be9facbe086

Wie gesagt, Laie ist wohl noch übertrieben.

Nicht ganz.

Willst mal testen, ob der auch geht:


void loop()
{
  static unsigned long startTime = 0;
  const unsigned long zeigeDisplay = 5000;
  enum {isclock, istemp, isdate};
  static byte mySwitch = isClock;
  readSerial();
  printText(0, MAX_DEVICES - 1, curMessage);
  intensity();
  buttonState1 = digitalRead(TasterDate);
  buttonState2 = digitalRead(TasterTemp);
  if (buttonState1 == LOW)
  {
    mySwitch = isdate;
    startTime = millis();
  }
  if (buttonState2 == LOW)
  {
    mySwitch = istemp;
    startTime = millis();
  }
  switch (mySwitch)
  {
    case isclock:
      setmessage_clock();
      break;
    case istemp:
      setmessage_temp();
      if (millis() - startTime > zeigeDisplay)
      {
        myStep = isClock;
      }
      break;
    case isdate:
      setmessage_date();
      if (millis() - startTime > zeigeDisplay)
      {
        myStep = isClock;
      }
      break;
    default:
      myStep = isclock;
      break;
  }
}

Das wäre übersichtlicher...

  • Wenn beim kompilieren Fehler drin sind, bitte erstmal selbst suchen :wink:

Das funktioniert ebenfalls... :wink:

Musste nur unten weiter myStep zu mySwitch abändern.
Muss aber sagen das es für mich nicht übersichtlicher geworden ist xD.
Aber ich hab da einen leisen Schimmer :sweat_smile: .

schön schön