Skip to content

Instantly share code, notes, and snippets.

@araffin
Last active April 2, 2018 19:15
Show Gist options
  • Save araffin/bc582e3678638568643ac9897cdbafd4 to your computer and use it in GitHub Desktop.
Save araffin/bc582e3678638568643ac9897cdbafd4 to your computer and use it in GitHub Desktop.
Example Use of Robust Serial in C++
// Extracted from https://github.com/araffin/cpp-arduino-serial/
#include <robust_serial.hpp>
// Open Serial Port
serial_file.open(serial_filename);
// Send the order "MOTOR", i.e. to change the speed of the car
write_order(serial_file, MOTOR);
// with parameter speed=56 (going forward at 56% of the maximum speed)
// The parameter "speed" is encoded as a 8 bits (1 bytes) signed int
write_i8(serial_file, 56);
// Send the order "SERVO", i.e. to change the direction of the car (the servomotor is controlled in angle)
write_order(serial_file, SERVO);
// parameter angle=156°
// The parameter "angle" is encoded as a 16 bits (2 bytes) signed int
write_i16(serial_file, 156);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment