Skip to content

Instantly share code, notes, and snippets.

@araffin
Last active April 8, 2018 12:18
Show Gist options
  • Save araffin/c63780845e089447dafcb77f2835e1fb to your computer and use it in GitHub Desktop.
Save araffin/c63780845e089447dafcb77f2835e1fb to your computer and use it in GitHub Desktop.
Example Use of Robust Serial in Rust
// Extracted from https://github.com/araffin/rust-arduino-serial
extern crate robust_arduino_serial;
use robust_arduino_serial::*;
// Open Serial Port
let mut port = serial::open(&serial_port).unwrap();
// Please see the original file to have a complete example
...
// Send the order "MOTOR", i.e. to change the speed of the car
// equivalent to write_i8(&mut port, Order::MOTOR as i8)
write_order(&mut port, Order::MOTOR).unwrap();
// 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(&mut port, 56_i8).unwrap();
// Send the order "SERVO", i.e. to change the direction of the car (the servomotor is controlled in angle)
write_order(&mut port, Order::SERVO).unwrap();
// with parameter angle=156°
// The parameter "angle" is encoded as a 16 bits (2 bytes) signed int
write_i16(&mut port, 156_i16).unwrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment