Venkata Arza
/
Slave_Main_Collision
Collision Slave for k64f
Embed:
(wiki syntax)
Show/hide line numbers
Slave_Main_Collision.cpp
00001 #include "mbed.h" 00002 #include "HCSR04.h" 00003 #define PIN_TRIGGER D0 00004 #define PIN_ECHO D1 00005 00006 Timeout response; 00007 00008 DigitalOut green(LED_GREEN); 00009 DigitalOut red(LED_RED); 00010 DigitalIn sw2(SW2); 00011 DigitalIn motion(D7); 00012 Serial pc(USBTX, USBRX ); 00013 00014 Serial blue(PTC15, PTC14); //tx, rx 00015 00016 00017 int main() 00018 { 00019 HCSR04 rangeFinder( PIN_TRIGGER, PIN_ECHO ); 00020 char send = 'Z'; 00021 int rangeFeet; 00022 float range; 00023 00024 pc.baud(9600); 00025 blue.baud(9600); 00026 00027 printf("Slave connecting to the master\n"); 00028 00029 //-------------------------------------------------------------------------- 00030 00031 while (true) { 00032 rangeFinder.startMeas(); 00033 wait(0.5f); 00034 if ( rangeFinder.getMeas(range) == RANGE_MEAS_VALID ) 00035 { 00036 00037 // printf("pre mod range = %f \n\r", range); 00038 range = (range * 100); 00039 // printf("post mod range = %f \n\r", range); 00040 rangeFeet = range; 00041 // printf("rangeFeet = %i \n\r", rangeFeet); 00042 } 00043 00044 00045 //-------------------------------------------------------------------------- 00046 00047 00048 if(blue.readable())//Determine if there is a character available to read. 00049 { 00050 if(rangeFeet > 2900) 00051 { 00052 rangeFeet = 0; 00053 } 00054 char word = (rangeFeet) + '0'; 00055 //printf("\n word = %c \n\r", word); 00056 blue.putc(word); 00057 } 00058 00059 00060 //-------------------------------------------------------------------------- 00061 wait(0.5f); // wait a small period of time 00062 green = !green; // toggle a led 00063 00064 } 00065 }
Generated on Tue Aug 2 2022 11:40:19 by 1.7.2