Shop OBEX P1 Docs P2 Docs Learn Events
Propeller / arduino syntax help — Parallax Forums

Propeller / arduino syntax help

Hello, i have a propeller that sends servo positions to other propellers and arduinos. all my code works but the arduino code is more cumbersome. I am trying to figure out how to write it so it ony uses one variable "servo1" like the propeller code?

propeller code...
//
servo1 = fdserial_rxChar(receive) << 7; //get Higher 7 bits
servo1 += fdserial_rxChar(receive) & 0x7F; //get and add Lower 7 bits
//

arduino code...
//
if (Serial1.available()) {
val1 = Serial1.read();
}
if (Serial1.available()) {
val2 = Serial1.read();
servo1 = (val1 << 7) | (val2);
}
//

Comments

  • Isn't that a question for the Arduino forums? I'm not much of an Arduino programmer, but here's an idea:

    if (Serial.available() > 1) {
      value = (Serial.read() << 7) || (Serial.read() & 0x7F);
    }
    

    You're using the .available() function as a Boolean when you can use it to check how many bytes are in the RX buffer.

  • Thanks Jon, ill give that a try. i stay away from the Arduino forum as much as possible its full of A-holes.

  • Understand. BTW, your Arduino code may be subject to a race condition where the first byte shows up between the first if clause and the second.

Sign In or Register to comment.