This is a check program for the Robocon Magazine.

Dependencies:   mbed

Committer:
yasuohayashibara
Date:
Wed Jan 16 16:02:29 2013 +0000
Revision:
0:8123026ac7a4
This is a check program for the Robocon Magazine.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yasuohayashibara 0:8123026ac7a4 1 #include "mbed.h"
yasuohayashibara 0:8123026ac7a4 2
yasuohayashibara 0:8123026ac7a4 3 PwmOut motor1(p26);
yasuohayashibara 0:8123026ac7a4 4 PwmOut motor2(p25);
yasuohayashibara 0:8123026ac7a4 5 PwmOut motor3(p24);
yasuohayashibara 0:8123026ac7a4 6 PwmOut motor4(p23);
yasuohayashibara 0:8123026ac7a4 7 DigitalOut myled(LED1);
yasuohayashibara 0:8123026ac7a4 8
yasuohayashibara 0:8123026ac7a4 9 #define PERIOD 0.00005
yasuohayashibara 0:8123026ac7a4 10
yasuohayashibara 0:8123026ac7a4 11 int motor(int right, int left)
yasuohayashibara 0:8123026ac7a4 12 {
yasuohayashibara 0:8123026ac7a4 13 if (right > 0) {
yasuohayashibara 0:8123026ac7a4 14 motor1.pulsewidth(0.0);
yasuohayashibara 0:8123026ac7a4 15 motor2.pulsewidth(PERIOD * right / 200);
yasuohayashibara 0:8123026ac7a4 16 } else {
yasuohayashibara 0:8123026ac7a4 17 motor1.pulsewidth(PERIOD * (- right) / 200);
yasuohayashibara 0:8123026ac7a4 18 motor2.pulsewidth(0.0);
yasuohayashibara 0:8123026ac7a4 19 }
yasuohayashibara 0:8123026ac7a4 20 if (left > 0) {
yasuohayashibara 0:8123026ac7a4 21 motor4.pulsewidth(0.0);
yasuohayashibara 0:8123026ac7a4 22 motor3.pulsewidth(PERIOD * left / 200);
yasuohayashibara 0:8123026ac7a4 23 } else {
yasuohayashibara 0:8123026ac7a4 24 motor4.pulsewidth(PERIOD * (- left) / 200);
yasuohayashibara 0:8123026ac7a4 25 motor3.pulsewidth(0.0);
yasuohayashibara 0:8123026ac7a4 26 }
yasuohayashibara 0:8123026ac7a4 27 return 0;
yasuohayashibara 0:8123026ac7a4 28 }
yasuohayashibara 0:8123026ac7a4 29
yasuohayashibara 0:8123026ac7a4 30
yasuohayashibara 0:8123026ac7a4 31 int main() {
yasuohayashibara 0:8123026ac7a4 32 motor1.period(PERIOD);
yasuohayashibara 0:8123026ac7a4 33 motor1.pulsewidth(0.0);
yasuohayashibara 0:8123026ac7a4 34 motor2.period(PERIOD);
yasuohayashibara 0:8123026ac7a4 35 motor2.pulsewidth(0.0);
yasuohayashibara 0:8123026ac7a4 36 motor3.period(PERIOD);
yasuohayashibara 0:8123026ac7a4 37 motor3.pulsewidth(0.0);
yasuohayashibara 0:8123026ac7a4 38 motor4.period(PERIOD);
yasuohayashibara 0:8123026ac7a4 39 motor4.pulsewidth(0.0);
yasuohayashibara 0:8123026ac7a4 40 int right = 0, left = 0, del = 10;
yasuohayashibara 0:8123026ac7a4 41 while(1){
yasuohayashibara 0:8123026ac7a4 42 myled = 1;
yasuohayashibara 0:8123026ac7a4 43 wait(0.2);
yasuohayashibara 0:8123026ac7a4 44 myled = 0;
yasuohayashibara 0:8123026ac7a4 45 wait(0.2);
yasuohayashibara 0:8123026ac7a4 46 right += del;
yasuohayashibara 0:8123026ac7a4 47 left += del;
yasuohayashibara 0:8123026ac7a4 48 if ((right >= 100)||(right <= -100)) del *= -1;
yasuohayashibara 0:8123026ac7a4 49 motor(right, left);
yasuohayashibara 0:8123026ac7a4 50 }
yasuohayashibara 0:8123026ac7a4 51 }
yasuohayashibara 0:8123026ac7a4 52