Venkata Arza
/
Slave_Main_Alert_copy
Goes with the Master_Main_Alert
Revision 0:fd80952fcd71, committed 2018-12-12
- Comitter:
- varza
- Date:
- Wed Dec 12 22:00:42 2018 +0000
- Commit message:
- Slave_Main_Alert
Changed in this revision
diff -r 000000000000 -r fd80952fcd71 HCSR04.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HCSR04.lib Wed Dec 12 22:00:42 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/rabad1/code/HCSR04/#5461d44a187c
diff -r 000000000000 -r fd80952fcd71 Slave_Main_Collision.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Slave_Main_Collision.cpp Wed Dec 12 22:00:42 2018 +0000 @@ -0,0 +1,65 @@ +#include "mbed.h" +#include "HCSR04.h" +#define PIN_TRIGGER D0 +#define PIN_ECHO D1 + +Timeout response; + +DigitalOut green(LED_GREEN); +DigitalOut red(LED_RED); +DigitalIn sw2(SW2); +DigitalIn motion(D7); +Serial pc(USBTX, USBRX ); + +Serial blue(PTC15, PTC14); //tx, rx + + +int main() +{ + HCSR04 rangeFinder( PIN_TRIGGER, PIN_ECHO ); + char send = 'Z'; + int rangeFeet; + float range; + + pc.baud(9600); + blue.baud(9600); + + printf("Slave connecting to the master\n"); + + //-------------------------------------------------------------------------- + + while (true) { + rangeFinder.startMeas(); + wait(0.5f); + if ( rangeFinder.getMeas(range) == RANGE_MEAS_VALID ) + { + + // printf("pre mod range = %f \n\r", range); + range = (range * 100); + // printf("post mod range = %f \n\r", range); + rangeFeet = range; + // printf("rangeFeet = %i \n\r", rangeFeet); + } + + + //-------------------------------------------------------------------------- + + + if(blue.readable())//Determine if there is a character available to read. + { + if(rangeFeet > 2900) + { + rangeFeet = 0; + } + char word = (rangeFeet) + '0'; + //printf("\n word = %c \n\r", word); + blue.putc(word); + } + + + //-------------------------------------------------------------------------- + wait(0.5f); // wait a small period of time + green = !green; // toggle a led + + } +} \ No newline at end of file
diff -r 000000000000 -r fd80952fcd71 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Dec 12 22:00:42 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc \ No newline at end of file