About InfraRed RemoteControl Programming Troubleshooting

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..

The incomplete code you posted has two while loops

#include <SPI.h>        //
#include <DMD.h>        //
#include <TimerOne.h>   //
#include "SystemFont5x7.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include <IRremote.h>
int RECV_PIN = 3;
#define code1  16724175
#define code2  16718055

IRrecv irrecv(RECV_PIN);
decode_results results;

#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}

void setup(void)
{

   
   Timer1.initialize( 3000 ); 
Timer1.attachInterrupt( ScanDMD );   
irrecv.enableIRIn(); 
   
   dmd.clearScreen( true );  
  Serial.begin(115200);
}

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(); 
   }

}}

sorry this is the full version

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.

#include <SPI.h>        //
#include <DMD.h>        //
#include <TimerOne.h>   //
#include "SystemFont5x7.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include <IRremote.h>
int RECV_PIN = 3;
#define code1  16724175
#define code2  16718055

IRrecv irrecv(RECV_PIN);
decode_results results;

#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);

void ScanDMD()
{
  dmd.scanDisplayBySPI();
}

void setup(void)
{

  Timer1.initialize( 3000 );
  Timer1.attachInterrupt( ScanDMD );
  irrecv.enableIRIn();

  dmd.clearScreen( true );
  Serial.begin(115200);
}

void loop(void)
{
  if (irrecv.decode(&results))
  {
    unsigned int value = results.value;
    switch (value)
    {
      case code1: //display message 1
        {
          dmd.clearScreen( true );
          dmd.selectFont(Arial_Black_16_ISO_8859_1);
          const char *MSG = "Message 1";
          dmd.drawMarquee(MSG, strlen(MSG), (32 * DISPLAYS_ACROSS) - 1, 0);
          value = 0;
          break
        }

      case code2:  //display message 2
        {
          dmd.clearScreen( true );
          dmd.selectFont(Arial_Black_16_ISO_8859_1);
          const char *MSG = "Message 2";
          dmd.drawMarquee(MSG, strlen(MSG), (32 * DISPLAYS_ACROSS) - 1, 0);
          value = 0;
          break;
        }

      case 0:  //scroll whatever message is being displayed
        dmd.stepMarquee(-1, 0);
        delay(100);
        break;
    }
  }
  irrecv.resume();
}

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.

#include <SPI.h>        //
#include <DMD.h>        //
#include <TimerOne.h>   //
#include "SystemFont5x7.h"
#include "Arial_Black_16_ISO_8859_1.h"
#include <IRremote.h>
int RECV_PIN = 3;
#define code1  16724175
#define code2  16718055

IRrecv irrecv(RECV_PIN);
decode_results results;

//Fire up the DMD library as dmd
#define DISPLAYS_ACROSS 1
#define DISPLAYS_DOWN 1
DMD dmd(DISPLAYS_ACROSS, DISPLAYS_DOWN);


void ScanDMD()
{
  dmd.scanDisplayBySPI();
}

void setup(void)
{    
	
	Timer1.initialize( 3000 );          
	Timer1.attachInterrupt( ScanDMD );   
	irrecv.enableIRIn(); 
	
	dmd.clearScreen( true );  
	Serial.begin(115200);
}


void loop(void)
{
	if (irrecv.decode(&results)) {
		unsigned int value = results.value;
		dmd.clearScreen( true );
		dmd.selectFont(Arial_Black_16_ISO_8859_1);
		long start = millis();
		long timer = start;
		while (true) {
			switch(value) {
				case code1:
                              {
					const char *MSG = "Message 1 ";
					break;
                               }
				case code2:
                               {
 					const char *MSG = "Message 2 ";
					break;

			}}
			
			if ((timer + 30) < millis()) {
					dmd.stepMarquee(-1, 0);
					timer = millis(); 
			}
			irrecv.resume();
		}
	}
}

I try to separate cases like this but this time there is nothing on led display

there is nothing on led display

That's because you don't appear to write to it.

Why did you ignore most of my suggested code ?