pixy info2

Dependencies:   CMPS03 SRF05 mbed pixy

Fork of 0000Non_stop_code_v3 by Alexandre Pirotte

Committer:
qj604184
Date:
Thu Jun 22 09:32:24 2017 +0000
Revision:
2:48f7e5f79caa
Parent:
0:a8cee96c9250
pixy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pirottealex 0:a8cee96c9250 1 #include "mbed.h"
pirottealex 0:a8cee96c9250 2 #include "fct.h"
pirottealex 0:a8cee96c9250 3 #include "SRF05.h"
pirottealex 0:a8cee96c9250 4
pirottealex 0:a8cee96c9250 5 void vitmoteur(float VitG, float VitD)
pirottealex 0:a8cee96c9250 6 {
pirottealex 0:a8cee96c9250 7 if(VitG<0) {
pirottealex 0:a8cee96c9250 8 VitG=-1*VitG;
pirottealex 0:a8cee96c9250 9 cmdI2C=cmdI2C&0xfe; //passe le moteur gauche en marche arriere 00000001
pirottealex 0:a8cee96c9250 10 } else {
pirottealex 0:a8cee96c9250 11 cmdI2C=cmdI2C|0x01; // marche avant 11110111 mot gauche
pirottealex 0:a8cee96c9250 12 }
pirottealex 0:a8cee96c9250 13 if(VitD<0) {
pirottealex 0:a8cee96c9250 14 VitD=-1*VitD;
pirottealex 0:a8cee96c9250 15 cmdI2C=cmdI2C&0xfd; //passe le moteur gauche en marche arriere 00000100
pirottealex 0:a8cee96c9250 16 } else {
pirottealex 0:a8cee96c9250 17 cmdI2C=cmdI2C|0x02;//marche avant 11111011 mot droit
pirottealex 0:a8cee96c9250 18 }
pirottealex 0:a8cee96c9250 19 monI2C.write(ADR_PCF,&cmdI2C,1);
pirottealex 0:a8cee96c9250 20 MotG.pulsewidth(((100-VitG)/100.0)*PERIOD);
pirottealex 0:a8cee96c9250 21 MotD.pulsewidth(((100-VitD)/100.0)*PERIOD);
pirottealex 0:a8cee96c9250 22 }
pirottealex 0:a8cee96c9250 23 void lecture_blanc(void)
pirottealex 0:a8cee96c9250 24 {
qj604184 2:48f7e5f79caa 25 if(C1.read()>0.8) {
pirottealex 0:a8cee96c9250 26 captL1=0;
qj604184 2:48f7e5f79caa 27 } else if(C1.read()<0.2) {
pirottealex 0:a8cee96c9250 28 captL1=1;
pirottealex 0:a8cee96c9250 29 }
qj604184 2:48f7e5f79caa 30 if(C3.read()>0.8) {
pirottealex 0:a8cee96c9250 31 captL3=0;
qj604184 2:48f7e5f79caa 32 } else if(C3.read()<0.2) {
pirottealex 0:a8cee96c9250 33 captL3=1;
pirottealex 0:a8cee96c9250 34 }
pirottealex 0:a8cee96c9250 35 }
pirottealex 0:a8cee96c9250 36
pirottealex 0:a8cee96c9250 37 void lecture_us(void)
pirottealex 0:a8cee96c9250 38 {
pirottealex 0:a8cee96c9250 39 us_arriere=us_arr.read();
qj604184 2:48f7e5f79caa 40 us_gauche=us_g.read();
qj604184 2:48f7e5f79caa 41 us_droit=us_d.read();
pirottealex 0:a8cee96c9250 42 }
pirottealex 0:a8cee96c9250 43
pirottealex 0:a8cee96c9250 44 void init(void)
pirottealex 0:a8cee96c9250 45 {
pirottealex 0:a8cee96c9250 46 bp.mode(PullUp);
pirottealex 0:a8cee96c9250 47 MotG.period(PERIOD);
pirottealex 0:a8cee96c9250 48 MotD.period(PERIOD);
pirottealex 0:a8cee96c9250 49 vitmoteur(0,0);
pirottealex 0:a8cee96c9250 50 }
pirottealex 0:a8cee96c9250 51
pirottealex 0:a8cee96c9250 52 void lecture_boussole(void)
pirottealex 0:a8cee96c9250 53 {
pirottealex 0:a8cee96c9250 54 gBoussole=Boussole.readBearing() / 10.0;
pirottealex 0:a8cee96c9250 55 }