机械臂控制代码
机机械械臂臂控控制制代代码码 集团标准化小组:[VVOPPT-JOPP28-JPPTL98-LOPPNN] ##include #include #include #include “Wire.h“ #include “WiiChuck.h“ Servo servo1;// create servo object to control a servo Servo servo2; Servo servo3; Servo servo4; // a maximum of eight servo objects can be created Servo servo5; Servo servo6; WiiChuck wii = WiiChuck(); int pos1,pos2,pos3,pos4,pos5,pos6,x,y,z,c; // variable to store the servo position void setup() { // attaches the servo on pin 9 to the servo object servo1.attach(8); servo2.attach(9); servo3.attach(10); servo4.attach(11); servo5.attach(12); servo6.attach(13); pos1 = 60; pos2 = 50; pos3 = 100; pos4 =100; pos5 = 90; pos6 = 90; servo1.write(pos1); servo2.write(pos2); servo3.write(pos3); servo4.write(pos4); servo5.write(pos5); servo6.write(pos6); wii.initWithPower(); } void loop() { if(true == wii.read() ) { //读取手柄值 x=wii.getJoyAxisX(); y=wii.getJoyAxisY(); c=wii.getButtonC(); z=wii.getButtonZ(); } if(x==255 servo1.write(pos1); } } else if(x==255 servo1.write(pos1); delay(40); if(pos1220 servo2.write(pos2); delay (40); if(pos2160) { pos2=160; servo2.write(pos2); } } else if(x220 servo2.write(pos2); delay(40); if(pos2110 servo3.write(pos3); } } else if(x110 servo3.write(pos3); delay(40); if(pos3160) { pos4=160; servo4.write(pos4); } } else if(x==0 servo4.write(pos4); delay(40); if(pos4170) { pos5=160; } } else if(x==0 pos5 = pos5-10; delay(40); if(pos5240 pos6 = pos6+10; delay (40); if(pos6120) { pos6=119; } } else if(x==0 pos6 = pos6-10; delay(40); if(pos645) { pos6=41; } } }