aggiornato con servomotore e display

Dependencies:   mbed Servo mbed-rtos beep hcsr04 TextLCD

Files at this revision

API Documentation at this revision

Comitter:
CiroSamu
Date:
Tue Apr 02 11:40:28 2019 +0000
Parent:
6:0088253be231
Commit message:
prog

Changed in this revision

Servo.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Tue Apr 02 11:40:28 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/ITI-DallaChiesa1/code/Servo/#de53826667ce
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Tue Apr 02 11:40:28 2019 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#e4cb7ddee0d3
--- a/main.cpp	Thu Mar 28 16:03:20 2019 +0000
+++ b/main.cpp	Tue Apr 02 11:40:28 2019 +0000
@@ -2,6 +2,8 @@
 #include "rtos.h"
 #include "hcsr04.h"
 #include "beep.h"
+#include "TextLCD.h"
+#include "Servo.h"
 #define trigger1 D15
 #define echo1 D14
 #define trigger2 D12
@@ -9,6 +11,8 @@
 /******************************/
 //bluetooth
 Serial pc(USBTX, USBRX);//tx e rx
+Servo servo(D9);
+TextLCD lcd(D10,D11,D5,D4,D3,D2);
 /******************************/
 //sensori ad ultrasuoni
 HCSR04 sensor1(trigger1, echo1);    
@@ -22,6 +26,7 @@
 /******************************/ 
  void button_thread(void const *args){
      bool sos= false;
+     int angle=0;
 //false== libero
 //true== occupato
     while(1){
@@ -33,9 +38,26 @@
             do{
                i++;
                if(occupata[i]== false){
-                    pc.printf("il parcheggio numero %d e libero\t",i);
+                    
+                    pc.printf("il parcheggio numero %d e libero\r\n",i);
+                    lcd.printf("il parcheggio numero %d e libero\r\n",i);
                     sos=true;
-                   // if(occupata[1]==true && occupata[2]==true) //sos = !sos;
+                    
+                while(1) {
+        servo.write(angle);
+        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);
+    }
+              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");
                     break;
@@ -43,7 +65,10 @@
            */
             }while(i<2);
            //  if(occupata[1]==true && occupata[2]==true) pc.printf("tutti i parcheggi sono occupati");
-        if(sos==false)                     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");
+        }
 
         }
         
@@ -53,14 +78,14 @@
 //sensore semaforo 1
 /******************************/
 void sensori(){
-        float distanza1;
-        float distanza2;
+       // float distanza1;
+       // float distanza2;
         sensor1.start();
         wait_ms(100);
         sensor2.start();         //partono i sensori 
         wait_ms(100);  
-        distanza1= sensor1.get_dist_cm() ;  
-        distanza2=sensor2.get_dist_cm();
+        //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() < 10.0 && occupata[1] ==  false)    //se uno dei sensori capta una distanza minore 10
             occupata[1] = true;