Skip to content

Instantly share code, notes, and snippets.

@legokichi
Last active August 29, 2015 14:03
Show Gist options
  • Save legokichi/3fa3800c9561c1c6a8a8 to your computer and use it in GitHub Desktop.
Save legokichi/3fa3800c9561c1c6a8a8 to your computer and use it in GitHub Desktop.
ArduinoからRoombaをSoftware Serialで動かす ref: http://qiita.com/DUxCA/items/36a13e68722c51c72927
#include <SoftwareSerial.h>;
SoftwareSerial device(10, 11);
void setup(){
device.begin(115200);
}
void loop(){}
#include <SoftwareSerial.h>;
SoftwareSerial device(10, 11);
void setup(){
device.begin(115200);
byte buffer[] = {
byte(128), // Start
byte(135) // Clean
};
device.write(buffer, 2);
}
void loop(){}
#include <SoftwareSerial.h>;
SoftwareSerial device(10, 11);
void setup(){
device.begin(115200);
}
void loop(){
motor(64, -64);
delay(250);
motor(-64, 64);
delay(250);
}
void motor(int l, int r){
byte buffer[] = {
byte(128), // Start
byte(132), // FULL
byte(146), // Drive PWM
byte(r>>8),
byte(r),
byte(l>>8),
byte(l)
};
device.write(buffer, 7);
}
#include <SoftwareSerial.h>;
SoftwareSerial device(10, 11);
void setup(){
Serial.begin(9600);
device.begin(115200);
}
void loop(){
if(Serial.available() > 0){
int cmd = Serial.read();
Serial.write(cmd);
switch(cmd){
case 48: motor( 64, 64); break; // forward
case 49: motor( 64, -64); break; // turnRight
case 50: motor(-64, 64); break; // turnLeft
case 51: motor(-64, -64); break; // back
default: motor( 0, 0); break; // stop
}
}else{
motor(0, 0);
}
delay(100);
}
void motor(int l, int r){
byte buffer[] = {
byte(128), // Start
byte(132), // FULL
byte(146), // Drive PWM
byte(r>>8),
byte(r),
byte(l>>8),
byte(l)
};
device.write(buffer, 7);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment