SyRen/Sabertooth Packet Serial Library for Arduino: 2.Settings/SerialTimeout/SerialTimeout.ino

SyRen/Sabertooth Packet Serial Library for Arduino

SyRen/Sabertooth Packet Serial Library for Arduino
Control your SyRen or Sabertooth with reliable Packet Serial.

Sets a serial timeout, and then delays to demonstrate its stopping behavior.

// Set Serial Timeout Sample for Packet Serial
// Copyright (c) 2012 Dimension Engineering LLC
// See license.txt for license details.
#include <Sabertooth.h>
Sabertooth ST(128);
void setup()
// setTimeout rounds up to the nearest 100 milliseconds, so this 950 will actually be 1 second.
// A value of 0 disables the serial timeout.
void loop()
// Set motor 1 to reverse 20 (out of 127), and sleep for 5 seconds.
// Notice how it cuts out after 1 second -- this is the serial timeout in action.
// Since we configured it in setup() for 1 second, 1 second without any new
// commands will cause the motors to stop.
ST.motor(1, -20);
// Why do this?
// If the S1 wire gets cut for some reason, or if your program crashes,
// the Sabertooth will stop receiving commands from the Arduino.
// With a timeout, your robot will stop. So, it's a safety feature mostly.