how to cancel out or ignore other ir signals


how block out other ir codes receiver accepts 1 signal not other?

i tried using else statement doesn't work example

} else {
        serial.println("ir signal received not recognized");
       

this program

#include <irremote.h>
#include <softwareserial.h>
#include <adafruit_neopixel.h>
#define pin 6

adafruit_neopixel strip = adafruit_neopixel(11 * 1, pin, neo_grb + neo_khz800);
irsend irsend;
softwareserial bt(0, 1); //tx, rx respetively
string readdata;
int vspeed = 100;
int recv_pin = 11;
irrecv irrecv(recv_pin);
decode_results results;
const int speakerpin   = 12;

int maxhealth          = 5;    // number of times can shot before dying
int myhealth           = maxhealth;
int deadtime           = 1000000000; // number of ms stay dead
int deathcount         = 0;

int hitstate           = high;
int lasthitstate       = high;

void setup() {
  bt.begin(9600);
  strip.begin();
  strip.show();
  serial.begin(9600);
  irrecv.enableirin();
  pinmode(9, output);
  pinmode(10, output);
  pinmode(5, output);
  pinmode(4, output);
  pinmode(speakerpin, output);
  colorwipe(strip.color(204, 0, 204), 10);

}
//-----------------------------------------------------------------------//
void loop(void) {
  while (bt.available()) { //check if there available byte read
    delay(10); //delay added make thing stable
    char c = bt.read(); //conduct serial read
    readdata += c; //build string- "forward", "reverse", "left" , "right"
  }
  if (readdata.length() > 0) {
    serial.println(readdata);


    if (readdata == "forward")
    {
      analogwrite(10, vspeed);
      analogwrite (9, low);
      analogwrite(5, vspeed);
      analogwrite(4, low);
      delay(100);
    }

    else if (readdata == "back")
    {
      analogwrite(10, low);
      analogwrite(9, vspeed);
      analogwrite(5, low);
      analogwrite(4, vspeed);
      delay(100);
    }

    else if (readdata == "right")
    {
      analogwrite (10, vspeed);
      analogwrite (9, low);
      analogwrite (5, low);
      analogwrite (4, low);
      delay (100);

    }

    else if ( readdata == "left")
    {
      analogwrite (10, low);
      analogwrite (9, high);
      analogwrite (5, vspeed);
      analogwrite (4, low);
      delay (100);
    }


    else if ( readdata == "reload")
    {
      rainbowcycle(5);
    }

    else if (readdata == "stop")
    {
      digitalwrite (10, low);
      digitalwrite (9, low);
      digitalwrite (5, low);
      digitalwrite (4, low);
      delay (100);
    }

    else if (readdata == "shoot")
    {
      irsend.sendnec(0x189710ef, 32);
      delay(40);
    }
    irrecv.enableirin();
    readdata = "";

  }

  //reset variable
  if (irrecv.decode(&results)) {
    serial.println(results.value, hex);

    if (results.value == 0xff30cf) {
      serial.println("hit");
      colorwipe(strip.color(255, 0, 0), 1); // red
      delay(100);
      colorwipe(strip.color(204, 0, 204), 10);
      myhealth--;
      if (myhealth <= 0) {
        serial.println("dead!");
        deathcount++;
        colorwipe(strip.color(255, 0, 0), 1);
        delay(deadtime);
        myhealth = maxhealth;
        serial.println("ready again!");

       
      } else {
        serial.println("ir signal received not recognized");
       
      }
     
      irrecv.resume(); // receive next value
     
    }
    delay(100);
  }
}
void colorwipe(uint32_t c, uint8_t wait) {
  (uint16_t = 0; < strip.numpixels(); i++) {
#ifdef debug
    serial.print("set pixel ");
    serial.print(i);
    serial.print(" of ");
    serial.print(strip.numpixels());
#endif
    strip.setpixelcolor(i, c);
#ifdef debug
    serial.println(" - ok");
#endif
    //delay(wait);
  }
  strip.show();
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  (j = 0; j < 256; j++) {
    (i = 0; < strip.numpixels(); i++) {
      strip.setpixelcolor(i, wheel((i + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// different, makes rainbow equally distributed throughout
void rainbowcycle(uint8_t wait) {
  uint16_t i, j;

  (j = 0; j < 256 * 5; j++) { // 5 cycles of colors on wheel
    (i = 0; < strip.numpixels(); i++) {
      strip.setpixelcolor(i, wheel(((i * 256 / strip.numpixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//theatre-style crawling lights.
void theaterchase(uint32_t c, uint8_t wait) {
  (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    (int q = 0; q < 3; q++) {
      (int = 0; < strip.numpixels(); = + 3) {
        strip.setpixelcolor(i + q, c);  //turn every third pixel on
      }
      strip.show();

      delay(wait);

      (int = 0; < strip.numpixels(); = + 3) {
        strip.setpixelcolor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

//theatre-style crawling lights rainbow effect
void theaterchaserainbow(uint8_t wait) {
  (int j = 0; j < 256; j++) {   // cycle 256 colors in wheel
    (int q = 0; q < 3; q++) {
      (int = 0; < strip.numpixels(); = + 3) {
        strip.setpixelcolor(i + q, wheel( (i + j) % 255)); //turn every third pixel on
      }
      strip.show();

      delay(wait);

      (int = 0; < strip.numpixels(); = + 3) {
        strip.setpixelcolor(i + q, 0);      //turn every third pixel off
      }
    }
  }
}

// input value 0 255 color value.
// colours transition r - g - b - r.
uint32_t wheel(byte wheelpos) {
  if (wheelpos < 85) {
    return strip.color(wheelpos * 3, 255 - wheelpos * 3, 0);
  } else if (wheelpos < 170) {
    wheelpos -= 85;
    return strip.color(255 - wheelpos * 3, 0, wheelpos * 3);
  } else {
    wheelpos -= 170;
    return strip.color(0, wheelpos * 3, 255 - wheelpos * 3);
  }
}

i solved it.

add irresume code higher receive loop


Arduino Forum > Using Arduino > Programming Questions > how to cancel out or ignore other ir signals


arduino

Comments

Popular posts from this blog

Help needed for choosing soldering station

Error Message when accessing Adobe

Fuelino for Arduino Nano - motorcycle Fuel Injection control and data logger