#include <Arduino.h>
#include "IBusBM.h"
IBusBM IBus;
int saveval = 0;

void setup()
{
  Serial.begin(115200);
  delay(100);
  IBus.begin(Serial2, IBUSBM_NOTIMER);
  delay(100);
  Serial.println("Start IBus2PWM_ESP32");
}

void loop()
{
  uint16_t val;
  IBus.loop();
    for (int i=0; i<10; i++) {
    Serial.print(IBus.readChannel(i));
    Serial.print(" ");
  }
  Serial.println("");
  val = IBus.readChannel(2); // get latest value for servo channel 1

  if (saveval != val)
  {
    //Serial.println(map(val, 1000, 2000, 0, 500));
    saveval = val;
  }

  delay(800);
}