|
楼主 |
发表于 2012-5-8 14:50:28
|
显示全部楼层
本帖最后由 sss_sxs 于 2012-5-8 14:52 编辑
//PROCESSING编程
import processing.serial.*;
Serial myport;
int count=0;
void setup()
{
size(480, 240);
smooth();
rect(100,20,40,40);
rect(20,100,40,40);
rect(100,100,40,40);
rect(180,100,40,40);
fill(0);
textSize(30);
text('w',110,48);
text('s',112,128);
text('a',30,128);
text('d',190,128);
fill(255);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(20,190,60,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(62,190,102,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(104,190,144,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(146,190,186,190);
smooth();
strokeWeight(1);
stroke(0, 0, 0);
triangle(360,18,330,70,390,70);
triangle(328,72,276,102,328,132);
triangle(330,134,360,186,390,134);
triangle(392,132,444,102,392,72);
rect(330,72,60,60);
textSize(11);
fill(0);
text("UP",355,58);
text("DOWN",345,155);
text("LEFT",300,107);
text("RIGHT",398,107);
textSize(13);
text("云台控制",334,107);
myport=new Serial(this,"COM3",19200);
count=0;
}
void draw()
{
if(keyPressed && key==CODED && keyCode==UP)
{
textSize(11);
fill(255,0,0);
text("UP",355,58);
myport.write(0x26);
}
else if(keyPressed && key==CODED && keyCode==DOWN)
{
textSize(11);
fill(255,0,0);
text("DOWN",345,155);
myport.write(0x28);
}
else if(keyPressed && key==CODED && keyCode==LEFT)
{
textSize(11);
fill(255,0,0);
text("LEFT",300,107);
myport.write(0x25);
}
else if(keyPressed && key==CODED && keyCode==RIGHT)
{
textSize(11);
fill(255,0,0);
text("RIGHT",398,107);
myport.write(0x27);
}
if(keyPressed && key == 'w')
{
myport.clear();
fill(255,0,0);
text('w',110,48);
myport.write('w');
}
else if(keyPressed && key == 's')
{
myport.clear();
fill(255,0,0);
text('s',112,128);
myport.write('s');
}
else if(keyPressed && key == 'a')
{
myport.clear();
fill(255,0,0);
text('a',30,128);
myport.write('a');
}
else if(keyPressed && key == 'd')
{
myport.clear();
fill(255,0,0);
text('d',190,128);
myport.write('d');
}
if(keyPressed && key == CODED)
{
if(keyCode==ALT && count == 1)
{
myport.clear();
fill(255);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(20,190,60,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(62,190,102,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(104,190,144,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(146,190,186,190);
myport.write(1);
}
}
if(keyPressed && key == CODED)
{
if(keyCode==ALT && count==2)
{
myport.clear();
fill(255);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(20,190,60,190);
fill(255);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(62,190,102,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(104,190,144,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(146,190,186,190);
myport.write(2);
}
}
if(keyPressed && key == CODED)
{
if(keyCode==ALT && count==3)
{
myport.clear();
fill(255);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(20,190,60,190);
fill(255);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(62,190,102,190);
fill(255);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(104,190,144,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(146,190,186,190);
myport.write(3);
}
}
if(keyPressed && key == CODED)
{
if(keyCode==ALT && count==4)
{
myport.clear();
fill(255);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(20,190,60,190);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(62,190,102,190);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(104,190,144,190);
stroke(30,144,255);
strokeWeight(20);
strokeCap(SQUARE);
line(146,190,186,190);
myport.write(4);
}
}
if(keyPressed && key == CODED)
{
if(keyCode==ALT && (count==5 || count==0))
{
myport.clear();
fill(255);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(20,190,60,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(62,190,102,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(104,190,144,190);
stroke(190);
strokeWeight(20);
strokeCap(SQUARE);
line(146,190,186,190);
myport.write(5);
}
}
if(count==5)
{
count=0;
}
}
void keyReleased()
{
fill(0);
textSize(30);
text('w',110,48);
text('s',112,128);
text('a',30,128);
text('d',190,128);
if(keyCode==UP)
{
textSize(11);
fill(0);
text("UP",355,58);
}
else if(keyCode==DOWN)
{
textSize(11);
fill(0);
text("DOWN",345,155);
}
else if(keyCode==LEFT)
{
textSize(11);
fill(0);
text("LEFT",300,107);
}
else if(keyCode==RIGHT)
{
textSize(11);
fill(0);
text("RIGHT",398,107);
}
}
void keyPressed()
{
if(keyCode==UP)
{
textSize(11);
fill(255,0,0);
text("UP",355,58);
}
else if(keyCode==DOWN)
{
textSize(11);
fill(255,0,0);
text("DOWN",345,155);
}
else if(keyCode==LEFT)
{
textSize(11);
fill(255,0,0);
text("LEFT",300,107);
}
else if(keyCode==RIGHT)
{
textSize(11);
fill(255,0,0);
text("RIGHT",398,107);
}
if(keyCode==ALT)
{
count++;
}
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|