interrupts question...

Good day to all members...is it possible if i put an input/output at ISR(interrupt service routine)?the code is like this..

void setup(){ ... attachInterrupt(0,ISR1,CHANGE); } void ISR1(){ irrecv.enableIRIn();

while(1==1)//infinite loop { switch(results.value==24145){ ... } irrecv.resume(); // Receive the next value }

is this code possible and correct?? my project is digital led signage and i am thinking of using interrupt and remote....please help everyone...

is this code possible and correct??

Absolutely and positively no.

An interrupt service routine is supposed to be very, very fast. The crystal oscillated a number of times; it's time to advance the time. The serial pin was toggled; it's time to read a character.

Putting an infinite loop in an ISR just plain will not work.

The IR library already uses interrupts to catch the incoming IR data. When sufficient data has been received, that data is available to use.

You would be better off testing for their being valid data to use, and using that data in loop(), rather than trying to use (incorrectly) any kind of interrupt.

If the problem is that your LED signage code is not responding to IR data, then the code needs to be restructured. Interrupts are not the answer to making the code stop dillydallying and start doing something different.

thank you very very very much sir for your quick reply... I was working on it a couple of days now I know its not possible... =( =( Is there any possible choice for my project to work sir?? The deadline is fast approaching sir, I really needed your help...Thank you sir..

I use this http://www.instructables.com/id/Make-a-24X6-LED-matrix/ as my guide sir...

If we had a better idea of what it is you want to do, what you have tried and how things went wrong, we might be able to help. In other words, post code.

while(1==1)//infinite loop

What are you thinking of? You want your ISR to loop infinitely? What purpose does that serve, sir?

The deadline is fast approaching ...

No doubt.

thank you to all of you... My project is digital led signage that can change the message wired or wireless sir...I manage to display the digital led signage sir my problem was how to change the message... I was planning to use the interrupt but now I know it is not possible I dont know what to do... Thank you very very very much guys... =( =(

I thought of using infinite loop to check the inputs sir NICK… I didnt know it was wrong… :blush:

I thought of using infinite loop to check the inputs

"loop()" is effectively an infinite loop. Have you tried doing what you want there?

yes sir AWOL Ive tried all my mind might think..and it doesn't work, I get headache and depress every time I got wrong... =( =(

People here are very knowledgeable and patient, but they are not psychic. If you want help, post code.

Hello there!.. I'm also a newbie here and in using arduino. I think this tutorial may help u sir, because your question is about interrupts. http://www.youtube.com/watch?v=vKVNmA8C6m8&feature=relmfu

Hoping that it can help you.

jogz44: ... sir AWOL ...

Looks like AWOL got a promotion! Congratulations.

jogz44: My project is digital led signage that can change the message wired or wireless sir...I manage to display the digital led signage sir my problem was how to change the message... I was planning to use the interrupt but now I know it is not possible I dont know what to do...

You can use interrupts to do things, but not the way you were. Perhaps more details, a circuit so we know what you are doing, and what code you have?

Looks like AWOL got a promotion! Congratulations.

Well, after hearing of my elevation to Shannon membership, Her Majesty has been gracious enough to confer a dubbing. Or did she say a drubbing?

Good day sir...here is the code sir..I am very sorry sir for the late reply, I was very busy because I help my classmates in preparing our upcoming festival...

http://www.mediafire.com/?0oir367jqp6m8m6

Good day sir NICK, here is the schematic sir... I was able to make it to 8 X 80 sir...

http://www.instructables.com/id/Make-a-24X6-LED-matrix/step3/Schematics/

how can I change the message sir??

thank you very much ma’am jen, the tutorial was all about wireless communication…I alreadey watch the interrupt tutorial ma’am and it was very helpful but I didnt know that my ideas were wrong…:frowning:

Would you please stop calling me “sir”? I haven’t been knighted.

void setupSPI(){// setting all the registers for SPI cummunication
  byte clr;
  SPCR |= ( (1<<SPE) | (1<<MSTR) ); // enable SPI as master
  //SPCR |= ( (1<<SPR1) | (1<<SPR0) ); // set prescaler bits
  SPCR &= ~( (1<<SPR1) | (1<<SPR0) ); // clear prescaler bits
  clr=SPSR; // clear SPI status reg
  clr=SPDR; // clear SPI data reg
  SPSR |= (1<<SPI2X); // set prescaler bits
  //SPSR &= ~(1<<SPI2X); // clear prescaler bits

  delay(10);
}
byte spi_transfer(byte data)
{
  SPDR = data;			  // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;			  // return the received byte, we don't need that
}

There is an SPI library you know. It works quite well.


void swap(){//changing message here
  irrecv.enableIRIn(); 
  while(1==1)
    {
    if (irrecv.decode(&results)) 
      {
      Serial.println(results.value, DEC);
      irrecv.resume(); 
      }
    if (results.value==16720095) 
      break;
    irrecv.resume(); 
    }
}

Your ISR is re-enabling interrupts which isn’t a particularly good idea (via irrecv.enableIRIn() ).

Going into a lengthy loop also isn’t a good idea.

I suggest you simply set a flag, eg.

volatile boolean button_pressed;

void swap()
  {
  button_pressed = true;
  }

Then test that flag in loop:

void loop() 
  {	
  display_word(1,your_text,11,40); 
  if (button_pressed)
    {
    irrecv.enableIRIn(); 
    while(true)  // loop until right button pressed ??
      {
      if (irrecv.decode(&results)) 
        {
        Serial.println(results.value, DEC);
        irrecv.resume(); 
        }
      if (results.value==16720095) 
        break;
      irrecv.resume(); 
     }
    button_pressed = false;
    }
  }

I’m not too sure about the test for 16720095. Does that mean your program simply stops until the right button is pressed?

Is it okay if I call you NICK?? but It is disrespect for me... :( by the way..I will try your solution right away... :)

You can call me Nick (not NICK). For me that is not disrespectful.

You will always be Mr. Gammon in my mind. ;)