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
Diff: main.cpp
- Revision:
- 4:48754f3702d7
- Parent:
- 3:272fb57c7fcb
- Child:
- 5:8eb27286a3e3
--- a/main.cpp Wed Mar 27 11:52:41 2019 +0000
+++ b/main.cpp Wed Mar 27 12:53:20 2019 +0000
@@ -2,21 +2,37 @@
#include "rtos.h"
#include "hcsr04.h"
#include "beep.h"
+#define trigger1 D15
+#define echo1 D14
+#define trigger2 D12
+#define echo2 D13
/******************************/
//bluetooth
Serial pc(USBTX, USBRX);//tx e rx
/******************************/
//sensori ad ultrasuoni
-HCSR04 sensor1(D2, D4); //istanza oggetti "sensori"
-HCSR04 sensor2(D7, D8);
+HCSR04 sensor1(trigger1, echo1);
+HCSR04 sensor2(trigger2, echo2);
//HCSR04 sensor3(D11, D9);
/******************************/
-
+//DigitalIn mybutton(USER_BUTTON);
Thread thread_sensori; // istanzia oggetto thread
bool occupata[2] = {false};
/******************************/
-
+ /*void button_thread(void const *args){
+
+ while(1){
+ if (mybutton==0){
+ sensor1.start();
+ sensor2.start();
+ //!mybutton;
+ }else break;
+
+ //tentativo di programmare un bottone
+
+ }
+}*/
//sensore semaforo 1
/******************************/
void sensori(){
@@ -38,23 +54,34 @@
}
int main(){
- pc.printf("prova");
+ // pc.printf("prova");
//while(true) {
-
+ //Thread button_th(button_thread);
+
sensori();
// blue.printf("prova");
- //if (mybutton) {
+ // if (mybutton==0) {
for (int i = 0; i < 2; i++)
{
- pc.printf("il parcheggio numero %d è libero", i + 1);
- break;
- //}
+ if(occupata[0]== false && occupata[1]== 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;
+ } else if(occupata[0]== true && occupata[1]== false){
+ pc.printf("il parcheggio numero %d è libero\n", i + 2 );
+ break;
+ }else{
+ pc.printf("appiennt\n");
+ break;
+ }
+
+ }
-
+ //}
-}
+
}
//void thread sensori() {