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
Revision 11:ae7f002fcdde, committed 2018-12-09
- Comitter:
- pinofal
- Date:
- Sun Dec 09 11:21:26 2018 +0000
- Parent:
- 10:fe07fdd23dec
- Commit message:
- Distanza tra 3 e 150 cm
Changed in this revision
StripLed-ProxSensor.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/StripLed-ProxSensor.cpp Fri Dec 07 17:02:54 2018 +0000 +++ b/StripLed-ProxSensor.cpp Sun Dec 09 11:21:26 2018 +0000 @@ -3,7 +3,7 @@ #include "mbed.h" // TimeOut in [microsec] per verificare la presenza del sensore prossimità. Se il sensore non è presente il timer supera TIMEOUTPROXSENSOR -#define TIMEOUTPROXSENSOR 1000 //tempo in [microsec] +#define TIMEOUTPROXSENSOR 16000 //tempo in [microsec] // seriale, pulsante Blu e LED verde su scheda Serial pc(USBTX, USBRX); @@ -68,7 +68,7 @@ OutBlue = 0; wait_ms(500); - + myLed=0; while(true) @@ -99,7 +99,7 @@ { nTimerCurrent = TimerProxSensor.read_us(); nTimerTillNow=nTimerCurrent-nTimerStart; - myLed=1; // se rimane nel while il LED rimane acceso + //myLed=1; // se rimane nel while il LED rimane acceso //pc.printf("sono qui 2 \r\n"); //scopi diagnostici } TimerProxSensor.stop(); // spegne il timer che serve per misurare il timeout quando assente il sensore di prossimità @@ -112,7 +112,7 @@ nTimerStart = TimerProxSensor.read_us(); while(InOutProxSensor == 1) { - myLed=1; // se rimane nel while il LED rimane acceso + //myLed=1; // se rimane nel while il LED rimane acceso } TimerProxSensor.stop(); nTimerStop = TimerProxSensor.read_us(); @@ -124,39 +124,41 @@ // distanza dell'ostacolo [cm] = (TimerStop-TimerStart)/2 [us] * 1/29.1[cm/us] fDistance = (nTimerStop-nTimerStart)/58.2; // invia il dato al PC - pc.printf("Distanza dall'ostacolo = %f0.2\r\n", fDistance); + //pc.printf("Distanza dall'ostacolo = %f0.2\r\n", fDistance); } else { // quando esce dai while bloccanti, il LED si spegne - myLed=0; - pc.printf("\r\nTimeOut\r\n"); + //myLed=0; // scopi diagnostici + pc.printf("\r\nTimeOut\r\n"); // scopi diagnostici } //++++++++++++++ FINE Acquisisci distanza ostacoli +++++++++ //++++++++++++++ INIZIO pilota accensione delle strip LED +++++++++++++++++++++++++ - //escludi le misure oltre il max - if((fDistance <= 50.0) && (fDistance >= 3)) + //escludi le misure oltre un range massimo e minimo. le distanze sono espress in [cm] + if((fDistance <= 150.0) && (fDistance >= 3.0)) { + // se un ostacolo si trova nel range di misura, accendi i LED OutRed = 1; - wait_ms(300); - //OutGreen.write_u16(32767); + wait_ms(100); OutGreen =1; - wait_ms(300); + wait_ms(100); OutBlue = 1; - wait_ms(300); - } + myLed=1; // scopi diagnostici + pc.printf("Distanza dell'ostacolo = %f0.2\r\n", fDistance); // scopi diagnostici + } else { OutRed = 0; - wait_ms(300); - //OutGreen.write_u16(0); + wait_ms(100); OutGreen =0; - wait_ms(300); + wait_ms(100); OutBlue = 0; - wait_ms(300); + myLed=0; // scopi diagnostici + pc.printf("Distanza dell'ostacolo fuori range = %f0.2\r\n", fDistance); // scopi diagnostici + } //++++++++++++++ FINE pilota accensione delle strip LED +++++++++++++++++++++++++ - wait_ms(200); + //wait_ms(100); }// while(true) }