Servo via bluetooth


can explain me. cant understand it. thanks

  if (serial.available() >= 2 )
  {
    unsigned int = serial.read();
    unsigned int b = serial.read();
    unsigned int val = (b * 256) + a;
    if (val >= 0 && val <= 180) // servo 1
    {
      servo1.write(val);
    }
    else if (val >= 1000 && val <= 1180) // servo 2
    {
      servo2.write(val-1000);
    }
    else if (val >= 2000 && val <= 2180) // servo 3
    {
      servo3.write(val-2000);
    }
    else if (val >= 3000 && val <= 3180) // servo 4
    {
      servo4.write(val-3000);
    }


attach here full sketch

suppose have number 60000 want send on serial interface, how when interface can send byte value 255 ?

one way split large number 2 bytes, send them , upon receipt recreate original number.  so, send 234 , 96.  upon receipt multiply 234 256 , 59904.  add 96 other byte , 60000.  how val created in program.

the program uses different values of val control 4 servos.  program sending data has create numbers , send appropriately servo controlled.


Arduino Forum > Using Arduino > Programming Questions > Servo via bluetooth


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???