ir receive code blocked by bt serial how to fix?


my receive code blocked when connect bt serial code. how program ir receive code works in harmony bt serial?


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

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


void setup() {
  serial1.begin(9600);
  strip.begin();
  strip.show();
  serial.begin(9600);
  irrecv.enableirin();
  pinmode(12, output);
  pinmode(10, output);
  pinmode(5, output);
  pinmode(11, output);
  colorwipe(strip.color(0, 0, 255), 10);

}
//-----------------------------------------------------------------------//
void loop(void) {
  while (serial1.available()) { //check if there available byte read
    delay(10); //delay added make thing stable
    char c = serial1.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 (12, low);
      analogwrite(5, vspeed);
      analogwrite(11, low);
      delay(100);
    }

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

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

    }

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


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

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

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


    readdata = "";

  }

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

    if (results.value == 0xff30cf) {
      serial.println("button1");
      colorwipe(strip.color(255, 0, 0), 1); // red
      delay(100);
      colorwipe(strip.color(0, 0, 255), 10);
    }
    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);
  }
}

irremote uses timer2 default , used pwm on pins 9 , 10.  since using pin 10 pwm output causing conflict.  read more irremote library see how select different timer.


Arduino Forum > Using Arduino > Programming Questions > ir receive code blocked by bt serial how to fix?


arduino

Comments

Popular posts from this blog

Help needed for choosing soldering station

Error Message when accessing Adobe

Adafruit Huzzah with Arduino Uno