This is a check program for the Robocon Magazine.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 PwmOut motor1(p26);
00004 PwmOut motor2(p25);
00005 PwmOut motor3(p24);
00006 PwmOut motor4(p23);
00007 DigitalOut myled(LED1);
00008 
00009 #define PERIOD 0.00005
00010 
00011 int motor(int right, int left)
00012 {
00013     if (right > 0) {
00014         motor1.pulsewidth(0.0);
00015         motor2.pulsewidth(PERIOD *    right  / 200);
00016     } else {
00017         motor1.pulsewidth(PERIOD * (- right) / 200);
00018         motor2.pulsewidth(0.0);
00019     }
00020     if (left > 0) {
00021         motor4.pulsewidth(0.0);
00022         motor3.pulsewidth(PERIOD *    left / 200);
00023     } else {
00024         motor4.pulsewidth(PERIOD * (- left) / 200);
00025         motor3.pulsewidth(0.0);
00026     }
00027     return 0;
00028 }
00029 
00030 
00031 int main() {
00032     motor1.period(PERIOD);
00033     motor1.pulsewidth(0.0);
00034     motor2.period(PERIOD);
00035     motor2.pulsewidth(0.0);
00036     motor3.period(PERIOD);
00037     motor3.pulsewidth(0.0);
00038     motor4.period(PERIOD);
00039     motor4.pulsewidth(0.0);
00040     int right = 0, left = 0, del = 10;
00041     while(1){
00042         myled = 1;
00043         wait(0.2);
00044         myled = 0;
00045         wait(0.2);
00046         right += del;
00047         left  += del;
00048         if ((right >= 100)||(right <= -100)) del *= -1;
00049         motor(right, left);
00050     }
00051 }
00052