Cat_Bot
/
Cat_Bot_sub
sub
Fork of Cat_Bot_sub by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "hcsr04.h" 00003 00004 Serial to_main(dp4,dp5); 00005 00006 HCSR04 front(dp24,dp25); 00007 HCSR04 back(dp22,dp23); 00008 HCSR04 right(dp20,dp21); 00009 HCSR04 left(dp18,dp19); 00010 00011 Ticker tick; 00012 00013 char dist[4]= {0}; 00014 00015 void put() 00016 { 00017 to_main.putc(1); 00018 to_main.putc(dist[0]); 00019 to_main.putc(dist[1]); 00020 to_main.putc(dist[2]); 00021 to_main.putc(dist[3]); 00022 } 00023 00024 int main() 00025 { 00026 to_main.baud(9600); 00027 tick.attach(&put, 0.05); 00028 while(1) { 00029 front.start(); 00030 back.start(); 00031 right.start(); 00032 left.start(); 00033 if(front.get_dist_cm()>255) 00034 dist[0]=255; 00035 else 00036 dist[0]=front.get_dist_cm(); 00037 if(back.get_dist_cm()>255) 00038 dist[1]=255; 00039 else 00040 dist[1]=back.get_dist_cm(); 00041 if(right.get_dist_cm()>255) 00042 dist[2]=255; 00043 else 00044 dist[2]=right.get_dist_cm(); 00045 if(left.get_dist_cm()>255) 00046 dist[3]=255; 00047 else 00048 dist[3]=left.get_dist_cm(); 00049 } 00050 }
Generated on Tue Jul 26 2022 06:21:10 by 1.7.2