Last active
April 2, 2018 19:15
-
-
Save araffin/bc582e3678638568643ac9897cdbafd4 to your computer and use it in GitHub Desktop.
Example Use of Robust Serial in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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