I need Help
in
Core Library Questions
•
8 months ago
I am making a ugv with arduino and this program will be run on the computer connected to a xbee.I am using the arrow keys to control but not working. i am new to programming.The numbers are for motor speed.
import processing.serial.*;
Serial myPort;
int portIndex = 0, rdir = 0, ldir = 0, rpow = 0, lpow = 0;
void setup()
{
myPort = new Serial(this, Serial.list()[portIndex], 9600);
}
void draw()
{
if( myPort.available() > 0)
{
myPort.write(ldir, rdir, rpow, lpow);
}
}
void keyPressed() {
{
if (key==LEFT)
{
rdir = 1;
ldir = 0;
}
else if (key==RIGHT)
{
rdir = 0;
ldir = 1;
}
else if (key==UP)
{
ldir = 1;
rdir = 1;
}
else if(key==DOWN)
{
rdir = 0;
ldir = 0;
}
}
if(key=='1')
{
lpow = 60;
rpow = 60;
}
else if(key=='2')
{
rpow = 120;
lpow = 120;
}
else if(key=='3')
{
rpow = 180;
lpow = 180;
}
else if(key=='4')
{
rpow = 240;
lpow = 240;
}
}
1