Anonym
05.01.2017, 14:34
Ich möchte meine Roboter (Arduino Uno, Pololu Dual Motor Driver Shield VNH5019) mit einem kablegebundenem XBox 360 Controller steuern.
Mein Arduino Code:
#include <DualVNH5019MotorShield.h>
#include <SoftwareSerial.h>
char val;
int x = 150;
int c = -150;
int i = 350;
int o = -350;
int p = 0;
int n = 250;
int m = -250;
DualVNH5019MotorShield md;
void setup()
{
md.init();
Serial.begin(115200);
}
void loop()
{
{
if (Serial.available())
{
val = Serial.read();
Serial.print(val);
}
else if (Serial.available())
{
val = Serial.read();
Serial.print(val);
}
}
// anfang motor steuerung 50%
if (val == 'W') {
md.setM1Speed(x);
md.setM2Speed(x);
}
if (val == '0') {
md.setM1Speed(p);
md.setM2Speed(p);
}
if (val == 'S') {
md.setM1Speed(c);
md.setM2Speed(c);
}
if (val == 'A') {
md.setM1Speed(x);
md.setM2Speed(c);
}
if (val == 'D') {
md.setM1Speed(c);
md.setM2Speed(x);
}
}
Mein Processing Code:
import processing.serial.*;
Serial port;
int val;
color currentcolor;
RectButton rect1, rect2, rect3, rect4, rect5;
boolean locked = false;
void setup() {
size(600, 600);
color baseColor = color(102, 102, 102);
currentcolor = baseColor;
port = new Serial(this, "/dev/ttyACM0", 115200);
// Define and create rectangle button #1
int x = 150;
int y = 250;
int size = 80;
color buttoncolor = color(153, 153, 153);
color highlight = color(102, 102, 102);
rect1 = new RectButton(x, y, size, buttoncolor, highlight);
// Define and create rectangle button #2
x = 250;
y = 250;
size = 80;
buttoncolor = color(153, 102, 102);
highlight = color(102, 102, 102);
rect2 = new RectButton(x, y, size, buttoncolor, highlight);
// Define and create rectangle button #3
x = 250;
y = 350;
size = 80;
buttoncolor = color(153, 153, 153);
highlight = color(102, 102, 102);
rect3 = new RectButton(x, y, size, buttoncolor, highlight);
// Define and create rectangle button #4
x = 250;
y = 150;
size = 80;
buttoncolor = color(153, 153, 153);
highlight = color(102, 102, 102);
rect4 = new RectButton(x, y, size, buttoncolor, highlight);
// Define and create rectangle button #5
x = 350;
y = 250;
size = 80;
buttoncolor = color(153, 153, 153);
Mein Ziel ist es, die Geschwindigkeit der Motoren möglichst genau mit dem XBox Controller zu steuern.
Danke für jede Hilfe
TCHD
Mein Arduino Code:
#include <DualVNH5019MotorShield.h>
#include <SoftwareSerial.h>
char val;
int x = 150;
int c = -150;
int i = 350;
int o = -350;
int p = 0;
int n = 250;
int m = -250;
DualVNH5019MotorShield md;
void setup()
{
md.init();
Serial.begin(115200);
}
void loop()
{
{
if (Serial.available())
{
val = Serial.read();
Serial.print(val);
}
else if (Serial.available())
{
val = Serial.read();
Serial.print(val);
}
}
// anfang motor steuerung 50%
if (val == 'W') {
md.setM1Speed(x);
md.setM2Speed(x);
}
if (val == '0') {
md.setM1Speed(p);
md.setM2Speed(p);
}
if (val == 'S') {
md.setM1Speed(c);
md.setM2Speed(c);
}
if (val == 'A') {
md.setM1Speed(x);
md.setM2Speed(c);
}
if (val == 'D') {
md.setM1Speed(c);
md.setM2Speed(x);
}
}
Mein Processing Code:
import processing.serial.*;
Serial port;
int val;
color currentcolor;
RectButton rect1, rect2, rect3, rect4, rect5;
boolean locked = false;
void setup() {
size(600, 600);
color baseColor = color(102, 102, 102);
currentcolor = baseColor;
port = new Serial(this, "/dev/ttyACM0", 115200);
// Define and create rectangle button #1
int x = 150;
int y = 250;
int size = 80;
color buttoncolor = color(153, 153, 153);
color highlight = color(102, 102, 102);
rect1 = new RectButton(x, y, size, buttoncolor, highlight);
// Define and create rectangle button #2
x = 250;
y = 250;
size = 80;
buttoncolor = color(153, 102, 102);
highlight = color(102, 102, 102);
rect2 = new RectButton(x, y, size, buttoncolor, highlight);
// Define and create rectangle button #3
x = 250;
y = 350;
size = 80;
buttoncolor = color(153, 153, 153);
highlight = color(102, 102, 102);
rect3 = new RectButton(x, y, size, buttoncolor, highlight);
// Define and create rectangle button #4
x = 250;
y = 150;
size = 80;
buttoncolor = color(153, 153, 153);
highlight = color(102, 102, 102);
rect4 = new RectButton(x, y, size, buttoncolor, highlight);
// Define and create rectangle button #5
x = 350;
y = 250;
size = 80;
buttoncolor = color(153, 153, 153);
Mein Ziel ist es, die Geschwindigkeit der Motoren möglichst genau mit dem XBox Controller zu steuern.
Danke für jede Hilfe
TCHD