test de la boussole

Dependencies:   CMPS03 mbed

Committer:
vermaelen
Date:
Wed May 31 08:49:23 2017 +0000
Revision:
2:fd17a1d6c0a3
Parent:
1:714fd6b732be
test boussole OK

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vermaelen 0:dcb865a03d57 1 #include "mbed.h"
vermaelen 2:fd17a1d6c0a3 2 #include "CMPS03.h"
vermaelen 2:fd17a1d6c0a3 3
vermaelen 0:dcb865a03d57 4 #define PERIOD 0.0001
vermaelen 0:dcb865a03d57 5
vermaelen 2:fd17a1d6c0a3 6 CMPS03 boussole(p9,p10,CMPS03_DEFAULT_I2C_ADDRESS);
vermaelen 0:dcb865a03d57 7
vermaelen 0:dcb865a03d57 8 BusOut leds(LED1,LED2,LED3,LED4);
vermaelen 2:fd17a1d6c0a3 9
vermaelen 0:dcb865a03d57 10 PwmOut MG(p21); //vitesse moteur gauche
vermaelen 0:dcb865a03d57 11 PwmOut MD(p24); //vitesse moteur droit
vermaelen 0:dcb865a03d57 12 DigitalOut sensMG(p23); // sens moteur gauche
vermaelen 0:dcb865a03d57 13 DigitalOut sensMD(p26); // sens moteur droit
vermaelen 0:dcb865a03d57 14
vermaelen 2:fd17a1d6c0a3 15 float vitesse(float vit)
vermaelen 2:fd17a1d6c0a3 16 {
vermaelen 2:fd17a1d6c0a3 17 if(vit<0) vit=0;
vermaelen 2:fd17a1d6c0a3 18 if(vit>60) vit=60;
vermaelen 2:fd17a1d6c0a3 19 return ((vit/100.0)*PERIOD);
vermaelen 2:fd17a1d6c0a3 20 }
vermaelen 0:dcb865a03d57 21
vermaelen 2:fd17a1d6c0a3 22
vermaelen 0:dcb865a03d57 23
vermaelen 0:dcb865a03d57 24 int main()
vermaelen 0:dcb865a03d57 25 {
vermaelen 0:dcb865a03d57 26
vermaelen 0:dcb865a03d57 27 sensMG.write(1);
vermaelen 0:dcb865a03d57 28 sensMD.write(1);
vermaelen 0:dcb865a03d57 29 MG.period(PERIOD);
vermaelen 0:dcb865a03d57 30 MD.period(PERIOD);
vermaelen 0:dcb865a03d57 31 MG.pulsewidth(vitesse(0));
vermaelen 0:dcb865a03d57 32 MD.pulsewidth(vitesse(0));
vermaelen 2:fd17a1d6c0a3 33
vermaelen 0:dcb865a03d57 34 while(1) {
vermaelen 2:fd17a1d6c0a3 35
vermaelen 2:fd17a1d6c0a3 36 printf("CAP=%.1f \n\r",boussole.readBearing()/10.0);
vermaelen 0:dcb865a03d57 37 wait(0.1);
vermaelen 0:dcb865a03d57 38 }
vermaelen 0:dcb865a03d57 39
vermaelen 2:fd17a1d6c0a3 40 }