dio
Dependencies: mbed mbed-rtos beep hcsr04
main.cpp@2:33e2a092cab6, 2019-03-27 (annotated)
- Committer:
- CiroSamu
- Date:
- Wed Mar 27 11:32:56 2019 +0000
- Revision:
- 2:33e2a092cab6
- Parent:
- 1:13556d8b4a34
- Child:
- 3:272fb57c7fcb
progetto
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
huntR | 0:650a24681467 | 1 | #include "mbed.h" |
huntR | 0:650a24681467 | 2 | #include "rtos.h" |
huntR | 0:650a24681467 | 3 | #include "hcsr04.h" |
huntR | 0:650a24681467 | 4 | #include "beep.h" |
huntR | 0:650a24681467 | 5 | /******************************/ |
huntR | 0:650a24681467 | 6 | //bluetooth |
CiroSamu | 2:33e2a092cab6 | 7 | Serial pc(USBTX, USBRX);//tx e rx |
huntR | 0:650a24681467 | 8 | /******************************/ |
huntR | 0:650a24681467 | 9 | //sensori ad ultrasuoni |
altoimperatore | 1:13556d8b4a34 | 10 | HCSR04 sensor1(D15, D14); //istanza oggetti "sensori" |
huntR | 0:650a24681467 | 11 | HCSR04 sensor2(D12, D13); |
CiroSamu | 2:33e2a092cab6 | 12 | //HCSR04 sensor3(D11, D9); |
huntR | 0:650a24681467 | 13 | /******************************/ |
altoimperatore | 1:13556d8b4a34 | 14 | |
altoimperatore | 1:13556d8b4a34 | 15 | Thread thread_sensori; // istanzia oggetto thread |
altoimperatore | 1:13556d8b4a34 | 16 | |
CiroSamu | 2:33e2a092cab6 | 17 | bool occupata[2] = {false}; |
huntR | 0:650a24681467 | 18 | /******************************/ |
huntR | 0:650a24681467 | 19 | |
huntR | 0:650a24681467 | 20 | //sensore semaforo 1 |
huntR | 0:650a24681467 | 21 | /******************************/ |
huntR | 0:650a24681467 | 22 | void sensori(){ |
huntR | 0:650a24681467 | 23 | sensor1.start(); |
huntR | 0:650a24681467 | 24 | wait_ms(100); |
altoimperatore | 1:13556d8b4a34 | 25 | sensor2.start(); //partono i sensori |
CiroSamu | 2:33e2a092cab6 | 26 | wait_ms(100); |
CiroSamu | 2:33e2a092cab6 | 27 | sensor1.get_dist_cm(); |
CiroSamu | 2:33e2a092cab6 | 28 | sensor2.get_dist_cm(); |
CiroSamu | 2:33e2a092cab6 | 29 | if(sensor1.get_dist_cm() < 5 && occupata[0] == false) //se uno dei sensori capta una distanza minore 10 |
altoimperatore | 1:13556d8b4a34 | 30 | occupata[0] = true; |
altoimperatore | 1:13556d8b4a34 | 31 | else |
altoimperatore | 1:13556d8b4a34 | 32 | occupata[0] = false; |
CiroSamu | 2:33e2a092cab6 | 33 | |
CiroSamu | 2:33e2a092cab6 | 34 | if(sensor2.get_dist_cm() < 5 && occupata[1] == false) //se uno dei sensori capta una distanza minore a 10 e gianello è false |
altoimperatore | 1:13556d8b4a34 | 35 | occupata[1] = true; |
altoimperatore | 1:13556d8b4a34 | 36 | else |
altoimperatore | 1:13556d8b4a34 | 37 | occupata[1] = false; |
CiroSamu | 2:33e2a092cab6 | 38 | } |
altoimperatore | 1:13556d8b4a34 | 39 | |
huntR | 0:650a24681467 | 40 | int main(){ |
CiroSamu | 2:33e2a092cab6 | 41 | pc.printf("prova"); |
altoimperatore | 1:13556d8b4a34 | 42 | while(true) { |
CiroSamu | 2:33e2a092cab6 | 43 | |
CiroSamu | 2:33e2a092cab6 | 44 | sensori(); |
CiroSamu | 2:33e2a092cab6 | 45 | // blue.printf("prova"); |
CiroSamu | 2:33e2a092cab6 | 46 | //if (mybutton) { |
altoimperatore | 1:13556d8b4a34 | 47 | for (int i = 0; i < 2; i++) |
altoimperatore | 1:13556d8b4a34 | 48 | pc.printf("%d", occupata[i]); |
CiroSamu | 2:33e2a092cab6 | 49 | } |
altoimperatore | 1:13556d8b4a34 | 50 | |
altoimperatore | 1:13556d8b4a34 | 51 | |
altoimperatore | 1:13556d8b4a34 | 52 | |
altoimperatore | 1:13556d8b4a34 | 53 | |
altoimperatore | 1:13556d8b4a34 | 54 | |
huntR | 0:650a24681467 | 55 | } |
altoimperatore | 1:13556d8b4a34 | 56 | |
altoimperatore | 1:13556d8b4a34 | 57 | |
CiroSamu | 2:33e2a092cab6 | 58 | //void thread sensori() { |
altoimperatore | 1:13556d8b4a34 | 59 | |
CiroSamu | 2:33e2a092cab6 | 60 | |
CiroSamu | 2:33e2a092cab6 | 61 | //} |