Mario Bambagini / Mbed 2 deprecated caterpillar

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "dc_motor.hpp"
00003 
00004 int main ()
00005 {
00006     AnalogIn vert(p20);
00007     AnalogIn horz(p19);
00008     DC_motor m_sx(p21, p22);
00009     DC_motor m_dx(p23, p24);
00010 
00011     while(1) {
00012         wait(0.2);
00013         float v = vert.read();
00014         float h = horz.read();
00015         float speed_sx = (v-0.5)*2.0;
00016         if (h>0.5)
00017             speed_sx *= (1.0-(h-0.5)*2.0);
00018         float speed_dx = (v-0.5)*2.0;
00019         if (h<0.5)
00020             speed_dx *= ((h+0.5)*2.0-1.0);
00021         m_sx.speed(speed_sx);
00022         m_dx.speed(speed_dx);
00023 //        printf("VERT(%f), HORZ(%f), sx(%f), dx(%f)\n\r",
00024 //                vert.read(), horz.read(), speed_sx, speed_dx);
00025     }
00026 }