軟體:ottoblockly
範例:向前走
arduino程式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <Otto.h> Otto Otto; #define LeftLeg 2 // left leg pin, servo[0] #define RightLeg 3 // right leg pin, servo[1] #define LeftFoot 4 // left foot pin, servo[2] #define RightFoot 5 // right foot pin, servo[3] #define Buzzer 13 //buzzer pin void setup() { Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); Otto.home(); // Here is where your robot is configured, the servo pins connections and buzzer } void loop() { Otto.walk(1,1000,1); // FORWARD } |
範例二、前進與後退
arduino程式:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <Otto.h> Otto Otto; #define LeftLeg 2 // left leg pin, servo[0] #define RightLeg 3 // right leg pin, servo[1] #define LeftFoot 4 // left foot pin, servo[2] #define RightFoot 5 // right foot pin, servo[3] #define Buzzer 13 //buzzer pin void setup() { Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); Otto.home(); } void loop() { Otto.walk(1,1000,1); // FORWARD delay(3*1000); Otto.walk(1,1000,-1); // BACKWARD delay(3*1000); } |
範例三、加上重覆迴圈
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <Otto.h> Otto Otto; #define LeftLeg 2 // left leg pin, servo[0] #define RightLeg 3 // right leg pin, servo[1] #define LeftFoot 4 // left foot pin, servo[2] #define RightFoot 5 // right foot pin, servo[3] #define Buzzer 13 //buzzer pin void setup() { Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); Otto.home(); } void loop() { for (int count=0 ; count<3 ; count++) { Otto.walk(1,1000,1); // FORWARD delay(3*1000); } for (int count=0 ; count<3 ; count++) { Otto.walk(1,1000,-1); // BACKWARD delay(3*1000); } } |
範例四、所有動作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <Otto.h> Otto Otto; #define LeftLeg 2 // left leg pin, servo[0] #define RightLeg 3 // right leg pin, servo[1] #define LeftFoot 4 // left foot pin, servo[2] #define RightFoot 5 // right foot pin, servo[3] #define Buzzer 13 //buzzer pin void setup() { Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); Otto.home(); } void loop() { for (int count=0 ; count<3 ; count++) { Otto.walk(1,1000,1); // FORWARD } delay(2*1000); for (int count=0 ; count<3 ; count++) { Otto.walk(1,1000,-1); // BACKWARD } delay(2*1000); for (int count=0 ; count<3 ; count++) { Otto.turn(1,1000,1); // LEFT } delay(2*1000); for (int count=0 ; count<3 ; count++) { Otto.turn(1,1000,-1); // RIGHT } delay(2*1000); for (int count=0 ; count<3 ; count++) { Otto.bend(1,1000,1); } delay(2*1000); for (int count=0 ; count<3 ; count++) { Otto.bend(1,1000,-1); } delay(2*1000); for (int count=0 ; count<3 ; count++) { Otto.shakeLeg(1,1000,-1); } delay(2*1000); for (int count=0 ; count<3 ; count++) { Otto.shakeLeg(1,1000,1); } delay(2*1000); for (int count=0 ; count<3 ; count++) { Otto.jump(1,1000); } delay(2*1000); } |
沒有留言:
張貼留言