PARCHEGGIO AMICO
Dependencies: mbed Servo mbed-rtos beep hcsr04 TextLCD
main.cpp@4:48754f3702d7, 2019-03-27 (annotated)
- Committer:
- CiroSamu
- Date:
- Wed Mar 27 12:53:20 2019 +0000
- Revision:
- 4:48754f3702d7
- Parent:
- 3:272fb57c7fcb
- Child:
- 5:8eb27286a3e3
progett
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" |
CiroSamu | 4:48754f3702d7 | 5 | #define trigger1 D15 |
CiroSamu | 4:48754f3702d7 | 6 | #define echo1 D14 |
CiroSamu | 4:48754f3702d7 | 7 | #define trigger2 D12 |
CiroSamu | 4:48754f3702d7 | 8 | #define echo2 D13 |
huntR | 0:650a24681467 | 9 | /******************************/ |
huntR | 0:650a24681467 | 10 | //bluetooth |
CiroSamu | 2:33e2a092cab6 | 11 | Serial pc(USBTX, USBRX);//tx e rx |
huntR | 0:650a24681467 | 12 | /******************************/ |
huntR | 0:650a24681467 | 13 | //sensori ad ultrasuoni |
CiroSamu | 4:48754f3702d7 | 14 | HCSR04 sensor1(trigger1, echo1); |
CiroSamu | 4:48754f3702d7 | 15 | HCSR04 sensor2(trigger2, echo2); |
CiroSamu | 2:33e2a092cab6 | 16 | //HCSR04 sensor3(D11, D9); |
huntR | 0:650a24681467 | 17 | /******************************/ |
CiroSamu | 4:48754f3702d7 | 18 | //DigitalIn mybutton(USER_BUTTON); |
altoimperatore | 1:13556d8b4a34 | 19 | Thread thread_sensori; // istanzia oggetto thread |
altoimperatore | 1:13556d8b4a34 | 20 | |
CiroSamu | 2:33e2a092cab6 | 21 | bool occupata[2] = {false}; |
huntR | 0:650a24681467 | 22 | /******************************/ |
CiroSamu | 4:48754f3702d7 | 23 | /*void button_thread(void const *args){ |
CiroSamu | 4:48754f3702d7 | 24 | |
CiroSamu | 4:48754f3702d7 | 25 | while(1){ |
CiroSamu | 4:48754f3702d7 | 26 | if (mybutton==0){ |
CiroSamu | 4:48754f3702d7 | 27 | sensor1.start(); |
CiroSamu | 4:48754f3702d7 | 28 | sensor2.start(); |
CiroSamu | 4:48754f3702d7 | 29 | //!mybutton; |
CiroSamu | 4:48754f3702d7 | 30 | }else break; |
CiroSamu | 4:48754f3702d7 | 31 | |
CiroSamu | 4:48754f3702d7 | 32 | //tentativo di programmare un bottone |
CiroSamu | 4:48754f3702d7 | 33 | |
CiroSamu | 4:48754f3702d7 | 34 | } |
CiroSamu | 4:48754f3702d7 | 35 | }*/ |
huntR | 0:650a24681467 | 36 | //sensore semaforo 1 |
huntR | 0:650a24681467 | 37 | /******************************/ |
huntR | 0:650a24681467 | 38 | void sensori(){ |
huntR | 0:650a24681467 | 39 | sensor1.start(); |
huntR | 0:650a24681467 | 40 | wait_ms(100); |
altoimperatore | 1:13556d8b4a34 | 41 | sensor2.start(); //partono i sensori |
CiroSamu | 2:33e2a092cab6 | 42 | wait_ms(100); |
CiroSamu | 2:33e2a092cab6 | 43 | sensor1.get_dist_cm(); |
CiroSamu | 2:33e2a092cab6 | 44 | sensor2.get_dist_cm(); |
CiroSamu | 2:33e2a092cab6 | 45 | if(sensor1.get_dist_cm() < 5 && occupata[0] == false) //se uno dei sensori capta una distanza minore 10 |
altoimperatore | 1:13556d8b4a34 | 46 | occupata[0] = true; |
altoimperatore | 1:13556d8b4a34 | 47 | else |
altoimperatore | 1:13556d8b4a34 | 48 | occupata[0] = false; |
CiroSamu | 2:33e2a092cab6 | 49 | |
CiroSamu | 2:33e2a092cab6 | 50 | 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 | 51 | occupata[1] = true; |
altoimperatore | 1:13556d8b4a34 | 52 | else |
altoimperatore | 1:13556d8b4a34 | 53 | occupata[1] = false; |
CiroSamu | 2:33e2a092cab6 | 54 | } |
altoimperatore | 1:13556d8b4a34 | 55 | |
huntR | 0:650a24681467 | 56 | int main(){ |
CiroSamu | 4:48754f3702d7 | 57 | // pc.printf("prova"); |
altoimperatore | 3:272fb57c7fcb | 58 | //while(true) { |
CiroSamu | 4:48754f3702d7 | 59 | //Thread button_th(button_thread); |
CiroSamu | 4:48754f3702d7 | 60 | |
CiroSamu | 2:33e2a092cab6 | 61 | sensori(); |
CiroSamu | 2:33e2a092cab6 | 62 | // blue.printf("prova"); |
CiroSamu | 4:48754f3702d7 | 63 | // if (mybutton==0) { |
altoimperatore | 1:13556d8b4a34 | 64 | for (int i = 0; i < 2; i++) |
altoimperatore | 3:272fb57c7fcb | 65 | { |
CiroSamu | 4:48754f3702d7 | 66 | if(occupata[0]== false && occupata[1]== false) pc.printf("il parcheggio numero %d è libero\n", i + 1 ); |
CiroSamu | 4:48754f3702d7 | 67 | else if(occupata[0]== false && occupata[1]== true){ |
CiroSamu | 4:48754f3702d7 | 68 | pc.printf("il parcheggio numero %d è libero\n", i + 1 ); |
CiroSamu | 4:48754f3702d7 | 69 | break; |
CiroSamu | 4:48754f3702d7 | 70 | } else if(occupata[0]== true && occupata[1]== false){ |
CiroSamu | 4:48754f3702d7 | 71 | pc.printf("il parcheggio numero %d è libero\n", i + 2 ); |
CiroSamu | 4:48754f3702d7 | 72 | break; |
CiroSamu | 4:48754f3702d7 | 73 | }else{ |
CiroSamu | 4:48754f3702d7 | 74 | pc.printf("appiennt\n"); |
CiroSamu | 4:48754f3702d7 | 75 | break; |
CiroSamu | 4:48754f3702d7 | 76 | } |
CiroSamu | 4:48754f3702d7 | 77 | |
CiroSamu | 4:48754f3702d7 | 78 | } |
altoimperatore | 1:13556d8b4a34 | 79 | |
altoimperatore | 1:13556d8b4a34 | 80 | |
CiroSamu | 4:48754f3702d7 | 81 | //} |
altoimperatore | 1:13556d8b4a34 | 82 | |
altoimperatore | 1:13556d8b4a34 | 83 | |
CiroSamu | 4:48754f3702d7 | 84 | |
altoimperatore | 3:272fb57c7fcb | 85 | } |
altoimperatore | 1:13556d8b4a34 | 86 | |
CiroSamu | 2:33e2a092cab6 | 87 | //void thread sensori() { |
altoimperatore | 1:13556d8b4a34 | 88 | |
CiroSamu | 2:33e2a092cab6 | 89 | |
CiroSamu | 2:33e2a092cab6 | 90 | //} |