aggiornato con servomotore e display

Dependencies:   mbed Servo mbed-rtos beep hcsr04 TextLCD

Committer:
altoimperatore
Date:
Wed Mar 27 11:52:41 2019 +0000
Revision:
3:272fb57c7fcb
Parent:
2:33e2a092cab6
Child:
4:48754f3702d7
progetto 3

Who changed what in which revision?

UserRevisionLine numberNew 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 3:272fb57c7fcb 10 HCSR04 sensor1(D2, D4); //istanza oggetti "sensori"
altoimperatore 3:272fb57c7fcb 11 HCSR04 sensor2(D7, D8);
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 3:272fb57c7fcb 42 //while(true) {
CiroSamu 2:33e2a092cab6 43
CiroSamu 2:33e2a092cab6 44 sensori();
CiroSamu 2:33e2a092cab6 45 // blue.printf("prova");
altoimperatore 3:272fb57c7fcb 46 //if (mybutton) {
altoimperatore 1:13556d8b4a34 47 for (int i = 0; i < 2; i++)
altoimperatore 3:272fb57c7fcb 48 {
altoimperatore 3:272fb57c7fcb 49 pc.printf("il parcheggio numero %d è libero", i + 1);
altoimperatore 3:272fb57c7fcb 50 break;
altoimperatore 3:272fb57c7fcb 51 //}
altoimperatore 1:13556d8b4a34 52
altoimperatore 1:13556d8b4a34 53
altoimperatore 1:13556d8b4a34 54
altoimperatore 1:13556d8b4a34 55
altoimperatore 1:13556d8b4a34 56
huntR 0:650a24681467 57 }
altoimperatore 3:272fb57c7fcb 58 }
altoimperatore 1:13556d8b4a34 59
CiroSamu 2:33e2a092cab6 60 //void thread sensori() {
altoimperatore 1:13556d8b4a34 61
CiroSamu 2:33e2a092cab6 62
CiroSamu 2:33e2a092cab6 63 //}