test ok de l'IUT GEII NICE
Dependencies: mbed LIDARLite_v3HP_IUT_GEII
main.cpp@0:854ff036e18c, 2022-02-09 (annotated)
- Committer:
- vermaelen
- Date:
- Wed Feb 09 15:17:50 2022 +0000
- Revision:
- 0:854ff036e18c
ca marche
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vermaelen | 0:854ff036e18c | 1 | #include "mbed.h" |
vermaelen | 0:854ff036e18c | 2 | #include "LIDARLite_v3HP.h" |
vermaelen | 0:854ff036e18c | 3 | DigitalOut myled(LED1); |
vermaelen | 0:854ff036e18c | 4 | I2C i2c(p9,p10); |
vermaelen | 0:854ff036e18c | 5 | LIDARLite_v3HP capteur(&i2c); |
vermaelen | 0:854ff036e18c | 6 | int main() |
vermaelen | 0:854ff036e18c | 7 | { |
vermaelen | 0:854ff036e18c | 8 | |
vermaelen | 0:854ff036e18c | 9 | |
vermaelen | 0:854ff036e18c | 10 | // capteur.configure(2,0x62); |
vermaelen | 0:854ff036e18c | 11 | while(1) { |
vermaelen | 0:854ff036e18c | 12 | capteur.takeRange(); |
vermaelen | 0:854ff036e18c | 13 | //capteur.waitForBusy(); |
vermaelen | 0:854ff036e18c | 14 | uint16_t val=capteur.readDistance(); |
vermaelen | 0:854ff036e18c | 15 | printf("d=%dcm\n\r",val); |
vermaelen | 0:854ff036e18c | 16 | wait(0.1); |
vermaelen | 0:854ff036e18c | 17 | } |
vermaelen | 0:854ff036e18c | 18 | } |
vermaelen | 0:854ff036e18c | 19 | |
vermaelen | 0:854ff036e18c | 20 | |
vermaelen | 0:854ff036e18c | 21 | |
vermaelen | 0:854ff036e18c | 22 | //le main qui fonctionne sans bibliothèque |
vermaelen | 0:854ff036e18c | 23 | |
vermaelen | 0:854ff036e18c | 24 | /* |
vermaelen | 0:854ff036e18c | 25 | int main(){ |
vermaelen | 0:854ff036e18c | 26 | char wait; |
vermaelen | 0:854ff036e18c | 27 | char start[2]={0,4}; |
vermaelen | 0:854ff036e18c | 28 | char reset[2]={0,0}; |
vermaelen | 0:854ff036e18c | 29 | char read=1; |
vermaelen | 0:854ff036e18c | 30 | char read_measureh=0xf; |
vermaelen | 0:854ff036e18c | 31 | char read_measurel=0x10; |
vermaelen | 0:854ff036e18c | 32 | char measureh,measurel; |
vermaelen | 0:854ff036e18c | 33 | char measure[2]; |
vermaelen | 0:854ff036e18c | 34 | i2c.write(0xC4,reset,2); //juste pour RESET le circuit , pas obligé |
vermaelen | 0:854ff036e18c | 35 | while(1){ |
vermaelen | 0:854ff036e18c | 36 | i2c.write(0xC4,start,2); //on lance la mesure |
vermaelen | 0:854ff036e18c | 37 | wait_us(100); |
vermaelen | 0:854ff036e18c | 38 | i2c.write(0xC4,&read,1); // on attend la réponse |
vermaelen | 0:854ff036e18c | 39 | do{ |
vermaelen | 0:854ff036e18c | 40 | |
vermaelen | 0:854ff036e18c | 41 | int rep=i2c.read(0xC4,&wait,1); |
vermaelen | 0:854ff036e18c | 42 | if(rep==1) |
vermaelen | 0:854ff036e18c | 43 | printf("c'est le bordel\n\r"); |
vermaelen | 0:854ff036e18c | 44 | else |
vermaelen | 0:854ff036e18c | 45 | //printf("wait=%x\n\r",wait); |
vermaelen | 0:854ff036e18c | 46 | putchar('.'); // pour voir le nombre de wait |
vermaelen | 0:854ff036e18c | 47 | }while((wait&1)!=0); |
vermaelen | 0:854ff036e18c | 48 | //on récup la mesure, obligé de faire la mesure octet par octet ???? |
vermaelen | 0:854ff036e18c | 49 | i2c.write(0xC4,&read_measureh,1); |
vermaelen | 0:854ff036e18c | 50 | i2c.read(0xC4,&measureh,1); |
vermaelen | 0:854ff036e18c | 51 | i2c.write(0xC4,&read_measurel,1); |
vermaelen | 0:854ff036e18c | 52 | i2c.read(0xC4,&measurel,1); |
vermaelen | 0:854ff036e18c | 53 | int value=(measureh<<8)+measurel; |
vermaelen | 0:854ff036e18c | 54 | printf("%x %x :val=%d cm\n\r",measureh,measurel,value); |
vermaelen | 0:854ff036e18c | 55 | |
vermaelen | 0:854ff036e18c | 56 | //ne fonctionne pas si on fait la mesure sur 2 octets, pas d'auto-incrément ????? |
vermaelen | 0:854ff036e18c | 57 | //i2c.write(0xC4,&read_measureh,1); |
vermaelen | 0:854ff036e18c | 58 | //i2c.read(0xC4,measure,2); |
vermaelen | 0:854ff036e18c | 59 | //int value=(measure[0]<<8)+measure[1]; |
vermaelen | 0:854ff036e18c | 60 | //printf("%x %x :val=%d cm\n\r",measure[0],measure[1],value); |
vermaelen | 0:854ff036e18c | 61 | wait_ms(50); |
vermaelen | 0:854ff036e18c | 62 | |
vermaelen | 0:854ff036e18c | 63 | } |
vermaelen | 0:854ff036e18c | 64 | }*/ |