Need help with Switch Case statements IR TV remote controlling LEDs


hello,

i'm trying make sketch 3 switch cases, , first case needs able loop on , on long condition satisfied (a decimal code sent tv remote arduino.  2nd case turning 1 of leds on, , default case leds off.

i need modifying code below first case can repeatable (like loop) 1 press of button, if button pressed, break out of "loop" or default condition seen.

code below , need know how make situation above work please:


#include <irremote.h>
int ir_recv = 3;

irrecv irrecv(ir_recv);
decode_results results;

void setup()
{
 
serial.begin(9600);
irrecv.enableirin();
pinmode(12, output);
pinmode(13, output);
}

void loop() {
  if(irrecv.decode(&results))
  {
    serial.println(results.value, hex);
    irrecv.resume();
    switch (results.value)
    {
      case 2464125561:
      digitalwrite(12, high);
      delay(500);
      digitalwrite(12, low);
      delay(500);
      digitalwrite(13, high);
      delay(500);
      digitalwrite(13, low);
      delay(500);
      break;
     
      case 2278412527:
      digitalwrite(12, low);
      digitalwrite(13, high);
      break;
     
      default:
      digitalwrite(12, low);
      digitalwrite(13, low);
    }
  irrecv.resume(); 

}
}

thank in advance this!

kevin

you should adjust thinking.  instead of thinking trapping code in loop inside switch statement, think instead fact loop function looping.  write code long condition stays true, code keeps landing in same section of switch statement , runs code once, on , on again.  use repeating nature of loop function work you. 

ie.  separate part of code checks signal , decodes part switch statement.  switch runs every time, regardless of whether or not there new code.


Arduino Forum > Using Arduino > Programming Questions > Need help with Switch Case statements IR TV remote controlling LEDs


arduino

Comments