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 mbed-rtos beep hcsr04
Revision 5:8eb27286a3e3, committed 2019-03-28
- Comitter:
- CiroSamu
- Date:
- Thu Mar 28 14:17:45 2019 +0000
- Parent:
- 4:48754f3702d7
- Commit message:
- prog
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 48754f3702d7 -r 8eb27286a3e3 main.cpp
--- a/main.cpp Wed Mar 27 12:53:20 2019 +0000
+++ b/main.cpp Thu Mar 28 14:17:45 2019 +0000
@@ -15,55 +15,78 @@
HCSR04 sensor2(trigger2, echo2);
//HCSR04 sensor3(D11, D9);
/******************************/
-//DigitalIn mybutton(USER_BUTTON);
-Thread thread_sensori; // istanzia oggetto thread
+DigitalIn mybutton(USER_BUTTON);
+//Thread thread_sensori; // istanzia oggetto thread
-bool occupata[2] = {false};
+bool occupata[3] = {false,false,false};
/******************************/
- /*void button_thread(void const *args){
+ void button_thread(void const *args){
while(1){
if (mybutton==0){
- sensor1.start();
- sensor2.start();
- //!mybutton;
- }else break;
+ int i=0;
+ do{
+ i++;
+ if(occupata[i]== false){
+ pc.printf("il parcheggio numero %d e libero\n",i);
+
+ }//else if(occupata[1]==true && occupata[2]==true) pc.printf("tutti i parcheggi sono occupati");
+
+ }while(occupata[i]== true && i<2);
+ }
- //tentativo di programmare un bottone
}
-}*/
+}
//sensore semaforo 1
/******************************/
void sensori(){
+ float distanza1;
+ float distanza2;
sensor1.start();
wait_ms(100);
- sensor2.start(); //partono i sensori
- wait_ms(100);
- sensor1.get_dist_cm();
- sensor2.get_dist_cm();
- if(sensor1.get_dist_cm() < 5 && occupata[0] == false) //se uno dei sensori capta una distanza minore 10
- occupata[0] = true;
- else
- occupata[0] = false;
-
- if(sensor2.get_dist_cm() < 5 && occupata[1] == false) //se uno dei sensori capta una distanza minore a 10 e gianello è false
+ sensor2.start(); //partono i sensori
+ wait_ms(100);
+ distanza1= sensor1.get_dist_cm() ;
+ distanza2=sensor2.get_dist_cm();
+ pc.printf("%.0fcm\r\n%.0fcm\r\n", distanza1,distanza2);
+ if(sensor1.get_dist_cm() < 5 && occupata[1] == false) //se uno dei sensori capta una distanza minore 10
occupata[1] = true;
else
occupata[1] = false;
+
+ if(sensor2.get_dist_cm() < 5 && occupata[2] == false) //se uno dei sensori capta una distanza minore a 10 e gianello è false
+ occupata[2] = true;
+ else
+ occupata[2] = false;
}
int main(){
// pc.printf("prova");
//while(true) {
//Thread button_th(button_thread);
+ //int i=0;
+
+ Thread button_th(button_thread);
+ while(1){
+ sensori();
+ }
- sensori();
// blue.printf("prova");
// if (mybutton==0) {
- for (int i = 0; i < 2; i++)
- {
- if(occupata[0]== false && occupata[1]== false) pc.printf("il parcheggio numero %d è libero\n", i + 1 );
+ /*
+ do{
+ i++;
+ if(occupata[i]== false){
+ pc.printf("il parcheggio numero %d è libero\n",i);
+
+ }
+
+
+ }while(occupata[i]== true && i<2);
+
+ */
+ /*if(occupata[i]== false && occupata[2]== false) pc.printf("il parcheggio numero %d è libero\n", i + 1 );
else if(occupata[0]== false && occupata[1]== true){
pc.printf("il parcheggio numero %d è libero\n", i + 1 );
break;
@@ -73,18 +96,18 @@
}else{
pc.printf("appiennt\n");
break;
- }
-
- }
+ }*/
+ // break;
+ // }
//}
-}
+
//void thread sensori() {
-
+
+}
-//}
\ No newline at end of file