void loop(void)
{
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
{
dmd.clearScreen( true );
dmd.selectFont(Arial_Black_16_ISO_8859_1);
// I
const char *MSG = "Message 1";
dmd.drawMarquee(MSG,strlen(MSG),(32*DISPLAYS_ACROSS)-1,0);
while(true){
dmd.stepMarquee(-1,0);
delay(100);
}
irrecv.resume();
break;
}
case code2:
dmd.clearScreen( true );
dmd.selectFont(Arial_Black_16_ISO_8859_1);
// I
const char *MSG = "Message 2";
dmd.drawMarquee(MSG,strlen(MSG),(32*DISPLAYS_ACROSS)-1,0);
while(1)
{
dmd.stepMarquee(-1,0);
delay(100);
}
irrecv.resume();
}
}}
In my project, I need to change the message on the led display via infrared remote control buttons but there is a problem because of the while loop, when I push the button 1 Message 1 come to the display but it is continuing and push the button 2 there is nothing to change so I need to control those loops for changing the buttons
I am waiting your replies Thanksss..
Use separate cases to write to the display and do the marquee. That way you can remove the while loops and use the switch/case to initialise the display then execute the marquee code. I would also suggest that you use millis() for timing instead of delay() in order to make the code more responsive to input.
void loop(void)
{
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
case code1:
{
dmd.clearScreen( true );
dmd.selectFont(Arial_Black_16_ISO_8859_1);
// I
const char *MSG = "Message 1";
dmd.drawMarquee(MSG,strlen(MSG),(32*DISPLAYS_ACROSS)-1,0);
long start=millis();
long timer=start;
while(true){
if ((timer+30) < millis()) {
dmd.stepMarquee(-1,0);
timer=millis();
}
irrecv.resume();
}
break;
}
case code2:
dmd.clearScreen( true );
dmd.selectFont(Arial_Black_16_ISO_8859_1);
// I
const char *MSG = "Message 2";
dmd.drawMarquee(MSG,strlen(MSG),(32*DISPLAYS_ACROSS)-1,0);
long start=millis();
long timer=start;
while(1){
if ((timer+30) < millis()) {
dmd.stepMarquee(-1,0);
timer=millis();
}
irrecv.resume();
}
break;
}}
}
Actually code was like this and think that delay or timer has the same functionality for my project and the cases are separate for message 1 and 2 and I can not understand your comment can you give me a little example plzz Thankss again..
It looks from your code as though you want to read an incoming code and depending on its value write a different message to the display and scroll the message across the display. However, you are using an infinite while loop to do the scrolling and when a new code is transmitted it is not read so the program does not respond.
You use switch/case to determine which message to display but you can make it do much more. Something like this untested code.
As to the use of delay(), I have left it in for now but it really would be better to use millis() timing to avoid the delay() program blocking and making the program less responsive than it could be.