I have a timing problem with the code below.
#include "LedControl.h"
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc = LedControl(12, 11, 10, 4);
/* we always wait a bit between updates of the display */
unsigned long delaytime = 500;
void setup() {
// initialize serial:
Serial.begin(9600);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0, false);
lc.shutdown(1, false);
lc.shutdown(2, false);
lc.shutdown(3, false);
/* Set the brightness to a medium values */
lc.setIntensity(0, 5);
lc.setIntensity(1, 5);
lc.setIntensity(2, 5);
lc.setIntensity(3, 5);
/* and clear the display */
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
}
void loop() {
if (Serial.available() > 0) {
}
Serial.flush();
delay(600);
lc.setDigit(0, 4, Serial.read() - '0', false);
lc.setDigit(0, 3, Serial.read() - '0', false);
lc.setDigit(0, 2, Serial.read() - '0', false);
lc.setDigit(0, 1, Serial.read() - '0', false);
lc.setDigit(0, 0, Serial.read() - '0', false);
lc.setDigit(1, 4, Serial.read() - '0', false);
lc.setDigit(1, 3, Serial.read() - '0', false);
lc.setDigit(1, 2, Serial.read() - '0', false);
lc.setDigit(1, 1, Serial.read() - '0', false);
lc.setDigit(1, 0, Serial.read() - '0', false);
// lc.setDigit(2, 4, Serial.read() - '0', false);
// lc.setDigit(2, 3, Serial.read() - '0', false);
lc.setDigit(2, 2, Serial.read() - '0', false);
lc.setDigit(2, 1, Serial.read() - '0', false);
lc.setDigit(2, 0, Serial.read() - '0', false);
// lc.setDigit(3, 4, Serial.read() - '0', false);
// lc.setDigit(3, 3, Serial.read() - '0', false);
lc.setDigit(3, 2, Serial.read() - '0', false);
lc.setDigit(3, 1, Serial.read() - '0', false);
lc.setDigit(3, 0, Serial.read() - '0', false);
}
When I send the string (in the form 1111122222333444 , numbers only) only once everything works without problems. Even if I send the code every few seconds everything is ok.
But I send him 2x per second get confused the numbers. I want as the last character Attach a "Z" or "*" and read only until then. I tried this code snippet. He shows no errors, but does not work either. The display is still messed up
while (Serial.available() > 0)
{
char recieved = Serial.read();
inData += recieved;
// Process message when new line character is recieved
if (recieved == 'Z')
{
// Get the code for displaying the values
inData = ""; // Clear recieved buffer
}
How do I solve this, which are always exactly read the 16 characters?
LCDemo7Segment.ino (2.01 KB)