cat_bot_sub

Dependencies:   HCSR04 mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "hcsr04.h"
00003 
00004 Serial to_main(dp4,dp5);
00005 //Serial pc(USBTX,USBRX);
00006 
00007 HCSR04 front(dp24,dp25);
00008 HCSR04 back(dp22,dp23);
00009 HCSR04 right(dp20,dp21);
00010 HCSR04 left(dp18,dp19);
00011 
00012 
00013 
00014 int main() {
00015     char dist[4]={0};
00016     //to_main.baud(19200);
00017     while(1) {
00018         front.start();
00019         back.start();
00020         right.start();
00021         left.start();
00022         if(front.get_dist_cm()>255)
00023             dist[0]=255;
00024         else
00025             dist[0]=front.get_dist_cm();
00026         if(back.get_dist_cm()>255)
00027             dist[1]=255;
00028         else
00029             dist[1]=back.get_dist_cm();
00030         if(right.get_dist_cm()>255)
00031             dist[2]=255;
00032         else
00033             dist[2]=right.get_dist_cm();
00034         if(left.get_dist_cm()>255)
00035             dist[3]=255;
00036         else
00037             dist[3]=left.get_dist_cm();
00038 
00039         to_main.putc(1);
00040         for(int i=0;i<4;i++){
00041             to_main.putc(dist[i]);
00042         }
00043         //pc.putc('\n');
00044     }
00045 }