here is my processing code i patched together:
import processing.serial.*;
Serial myport;
int val;
void Setup()
{
size(200,200);
String portName = Serial.list()[4];
myport = new Serial(this, portName, 9600);
}
void draw() {
background(255,255,0,255);
}
void keyPressed() {
if (key == CODED){
if (key == UP) {
myport.write('F');
}
else if (key == DOWN){
myport.write('B');
}
else if (key == LEFT){
myport.write('L');
}
else if (key == RIGHT){
myport.write('R');
}
else{
myport.write('S');
}
}
}
and arduino:
#include <Servo.h>
Servo Left;
Servo Right;
//int Lspeed = 0;
//int Rspeed = 0;
int val;
void setup() {
Left.attach(12);
Right.attach(13);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
val = Serial.read();
}
if (val == 'F') { // If Forward command was received
Left.write(180); // go forward
Right.write(0); //invert direction for opposite motors
}
else if (val == 'B') {
Left.write(0);
Right.write(180);
}
else if (val == 'R') {
Left.write(0);
Right.write(0);
}
else if (val == 'L') {
Left.write(180);
Right.write(0);
}
else {
Left.write(90);
Right.write(90);
}
delay(100); // Wait 100 milliseconds for next reading
}
should this work? unfortunately I don't have any 360 degree servos to test this with at the moment...
Anyone can feel free to test this- just connect your servos to pins 12 and 13.