Skip to content

Instantly share code, notes, and snippets.

@dannystaple
Last active December 29, 2015 00:29
Show Gist options
  • Save dannystaple/7585942 to your computer and use it in GitHub Desktop.
Save dannystaple/7585942 to your computer and use it in GitHub Desktop.
Code for Bluetooth Orion Explorer 1 Tutorial
#include "SoftwareSerial.h"
#include "TurtleMotors.h"
//Define the devices
Motor motor_left = {10, 8, 9};
Motor motor_right = {3, 4, 5};
TurtleMotors motors = {motor_left, motor_right, 255, 100};
SoftwareSerial mySerial(11, 12); // RX, TX
void setup() {
mySerial.begin(9600);
motors.setup();
}
unsigned long timeout = 0;
void loop() {
if(mySerial.available()) {
char data = (char)mySerial.read();
timeout = millis() + 1000;
switch(data) {
case 'w':
motors.forward(0);
break;
case 's':
motors.backward(0);
break;
case 'a':
motors.turnLeft(0);
break;
case 'd':
motors.turnRight(0);
break;
default:
motors.stop();
break;
}
}
else {
if (millis() > timeout) {
motors.stop();
}
}
}
void setup() {
setup software serial
setup motors
}
void loop() {
if there is data on the serial port {
reset timeout
read it
when the data is {
'w' : go forward
's' : go backwards
'a' : go left,
'd' : go right,
' ' : stop,
}
}
else if (timed out) {
stop
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment