Etienne Stransky
/
Tests_detecteur_ultrasons
ok
main.cpp@0:22ab0837ece5, 2019-02-12 (annotated)
- Committer:
- stersky
- Date:
- Tue Feb 12 14:50:38 2019 +0000
- Revision:
- 0:22ab0837ece5
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stersky | 0:22ab0837ece5 | 1 | #include "mbed.h" |
stersky | 0:22ab0837ece5 | 2 | |
stersky | 0:22ab0837ece5 | 3 | Serial pc(USBTX, USBRX); //Initialise une liason série via le connecteur USB du pc |
stersky | 0:22ab0837ece5 | 4 | I2C ultrason(p9,p10); //Initialise une connexion i2c sur p9 et p10 |
stersky | 0:22ab0837ece5 | 5 | |
stersky | 0:22ab0837ece5 | 6 | int main() |
stersky | 0:22ab0837ece5 | 7 | { |
stersky | 0:22ab0837ece5 | 8 | |
stersky | 0:22ab0837ece5 | 9 | int adresse=0xE0 ; |
stersky | 0:22ab0837ece5 | 10 | ultrason.frequency(50000); |
stersky | 0:22ab0837ece5 | 11 | pc.baud(115200);//Initialise la vitesse de la communication série |
stersky | 0:22ab0837ece5 | 12 | |
stersky | 0:22ab0837ece5 | 13 | char config[2]; char lecture[2]; int mesure = 5; |
stersky | 0:22ab0837ece5 | 14 | |
stersky | 0:22ab0837ece5 | 15 | while(1) { |
stersky | 0:22ab0837ece5 | 16 | config[0]= 0x00; |
stersky | 0:22ab0837ece5 | 17 | config[1]= 0x51; |
stersky | 0:22ab0837ece5 | 18 | ultrason.write(adresse, config, 2); |
stersky | 0:22ab0837ece5 | 19 | |
stersky | 0:22ab0837ece5 | 20 | wait_ms(100); |
stersky | 0:22ab0837ece5 | 21 | |
stersky | 0:22ab0837ece5 | 22 | config[0]= 0x02; |
stersky | 0:22ab0837ece5 | 23 | ultrason.write(adresse, config, 1); |
stersky | 0:22ab0837ece5 | 24 | |
stersky | 0:22ab0837ece5 | 25 | ultrason.read(adresse, lecture, 2); |
stersky | 0:22ab0837ece5 | 26 | |
stersky | 0:22ab0837ece5 | 27 | |
stersky | 0:22ab0837ece5 | 28 | pc.printf("Distance : %d cm\n\r",lecture[1]); |
stersky | 0:22ab0837ece5 | 29 | |
stersky | 0:22ab0837ece5 | 30 | } |
stersky | 0:22ab0837ece5 | 31 | |
stersky | 0:22ab0837ece5 | 32 | } |