Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Servo mbed-rtos beep hcsr04 TextLCD
Revision 10:2fd7e922103f, committed 2019-04-09
- Comitter:
- altoimperatore
- Date:
- Tue Apr 09 09:56:34 2019 +0000
- Parent:
- 9:5be4a23d1e86
- Commit message:
- Lavoro terminato
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Apr 04 12:55:52 2019 +0000
+++ b/main.cpp Tue Apr 09 09:56:34 2019 +0000
@@ -28,7 +28,7 @@
DigitalIn mybutton(D7); //istanza oggetto bottone
//Thread thread_sensori; // istanzia oggetto thread
-bool occupata[5] = { false, false, false,false};
+bool occupata[5] = { false, false, false,false, false};
int numero_parcheggi = 4;
//dichiarazione vettore booleano che indica gli stati del parcheggio
@@ -57,26 +57,33 @@
if(occupata[i] == false)
{
- pc.printf("il parcheggio numero %d e libero\r\n", i); //stampa quali parcheggi sono liberi
- lcd.printf("il parcheggio numero %d e libero\r\n", i);
- sos = true; //se un parcheggio è libero conseguentemente non possono essere tutti occupati
- while(1)
+ if(sos == false)
+ {
+
+ pc.printf(" parcheggio %d \r\n", i); //stampa quali parcheggi sono liberi
+ lcd.cls();
+ lcd.printf(" parcheggio %d \r\n", i);
+
+ sos = true;
+ break;
+ } //se un parcheggio è libero conseguentemente non possono essere tutti occupati
+ while(1)
+ {
+ servo.write(angle); //non toccare
+ angle += 10;
+ if(angle > 90)
+ {
+ wait(3);
+ while(angle != 0 )
{
- servo.write(angle); //non toccare
- angle += 10;
- if(angle > 90)
- {
- wait(3);
- while(angle != 0 )
- {
- servo.write(angle);
- angle -= 10;
- wait(0.25);
- }
- if(angle == 0) break;
- }
- wait(0.25);
- }
+ servo.write(angle);
+ angle -= 10;
+ wait(0.25);
+ }
+ if(angle == 0) break;
+ }
+ wait(0.25);
+ }
//if(occupata[1] == false && occupata[2] == false) break; // if(occupata[1]==true && occupata[2]==true) //sos = !sos;
}/*else if(sos==false && i==2){
pc.printf("tutti i parcheggi sono occupati");
@@ -84,24 +91,48 @@
}//else if(occupata[1]==true && occupata[2]==true) pc.printf("tutti i parcheggi sono occupati");
*/
- } while(1); // ciclo infinito, segnalera sempre i parcheggi liberi
+ } while(1);
+
+ if(sos == true)
+ {
+ while(1)
+ {
+ servo.write(angle); //non toccare
+ angle += 10;
+ if(angle > 90)
+ {
+ wait(3);
+ while(angle != 0 )
+ {
+ servo.write(angle);
+ angle -= 10;
+ wait(0.25);
+ }
+ if(angle == 0) break;
+ }
+ wait(0.25);
+ }
+ } // ciclo infinito, segnalera sempre i parcheggi liberi
// if(occupata[1]==true && occupata[2]==true) pc.printf("tutti i parcheggi sono occupati");
if (sos == false)
{
- pc.printf("tutti i parcheggi sono occupati\r\n");
- lcd.printf("tutti i parcheggi sono occupati\r\n");
+ pc.printf("parcheggio pieno");
+ lcd.cls();
+ lcd.printf("parcheggio pieno");
+
+
}
- else
+ /*else
{
lcd.printf("per riavviare premere l'apposito pulsante");
pc.printf("per riavviare premere l'apposito pulsante");
- }
+ }*/
}//if pulsante
- }//chiusura iterazione del pulsante
-}// chiusura funzione
-//sensore semaforo 1
+ }
+}
+
/******************************/
void sensori()
{
@@ -116,13 +147,11 @@
wait_ms(100);
sensor4.start();
wait_ms(100);
- /* distanza1=sensor1.get_dist_cm();
- distanza2=sensor2.get_dist_cm();
- distanza3=sensor3.get_dist_cm();
- pc.printf("sensore1 %.0fcm\r\n\nsensore2 %.0fcm\r\n\nsensore3 %.0fcm\r\n\n", distanza1,distanza2,distanza3);*/
+ bool sos;
+
if(sensor1.get_dist_cm() <= 10.0) occupata[1] = true;
else occupata[1] = false;
-
+
if(sensor2.get_dist_cm() <= 10.0) occupata[2] = true;
else occupata[2] = false;
@@ -131,17 +160,13 @@
if(sensor4.get_dist_cm() <= 10.0) occupata[4] = true;
else occupata[4] = false;
-
-
-}
+}
-int main(){
- // pc.printf("prova");
- //while(true) {
- //Thread button_th(button_thread);
- //int i=0;
-
+int main()
+{
+
Thread button_th(button_thread);
+
while(1)
{
sensori();