christophe vermaelen / Mbed 2 deprecated _cachan_test_boussole

Dependencies:   CMPS03 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "CMPS03.h"
00003 
00004 #define PERIOD 0.0001
00005 
00006 CMPS03 boussole(p9,p10,CMPS03_DEFAULT_I2C_ADDRESS);
00007 
00008 BusOut leds(LED1,LED2,LED3,LED4);
00009 
00010 PwmOut MG(p21); //vitesse moteur gauche
00011 PwmOut MD(p24); //vitesse moteur droit
00012 DigitalOut sensMG(p23);  // sens moteur gauche
00013 DigitalOut sensMD(p26);  // sens moteur droit
00014 
00015 float vitesse(float vit)
00016 {
00017     if(vit<0) vit=0;
00018     if(vit>60) vit=60;
00019     return ((vit/100.0)*PERIOD);
00020 }
00021 
00022 
00023 
00024 int main()
00025 {
00026 
00027     sensMG.write(1);
00028     sensMD.write(1);
00029     MG.period(PERIOD);
00030     MD.period(PERIOD);
00031     MG.pulsewidth(vitesse(0));
00032     MD.pulsewidth(vitesse(0));
00033     
00034     while(1) {
00035         
00036         printf("CAP=%.1f \n\r",boussole.readBearing()/10.0);
00037         wait(0.1);
00038     }
00039 
00040 }