m3pi raw sensorを使ったライントレース

Dependencies:   mbed m3pi

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "m3pi.h"
00003 
00004 m3pi m3pi;
00005 int main() {
00006     unsigned char x[10];
00007     int i;
00008     while(1) {
00009         m3pi.putc(0x86);
00010         for(i=0;i<10;i++){
00011             x[i]=m3pi.getc();
00012         }
00013         m3pi.locate(0,0);
00014         m3pi.printf(" %2x  %2x",(x[3]*0x100+x[2])/8,(x[7]*0x100+x[6])/8);
00015         m3pi.locate(0,1);
00016         m3pi.printf("%2x %2x %2x",(x[1]*0x100+x[0])/8,(x[5]*0x100+x[4])/8,(x[9]*0x100+x[8])/8);
00017         if(x[1]*0x100+x[0]>x[9]*0x100+x[8]){
00018             m3pi.left_motor(0.5);
00019             m3pi.right_motor(0);
00020         }else{
00021             m3pi.left_motor(0);
00022             m3pi.right_motor(0.5);
00023         }
00024     }
00025 }