Interface class for the Max Botix ultrasonic range finder model 1210. It includes input methods for PWM, Analog, and Serial. A PwmIn class was created to allow the PWM input to be read. Now includes automatic range update via interrupts.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MB1210.h"
00003 
00004 DigitalOut debugled(LED1);
00005 Serial Computer(USBTX, USBRX);
00006 
00007 MB1210 RangeFinder(p12, p15, p13, p14);
00008 float Range;
00009 int main()
00010 {
00011     Computer.baud(9600);
00012     debugled = 0;
00013     RangeFinder.Unit(39.370);//change units to inches
00014     RangeFinder.AttachInterruptBuffer(&Range);
00015     RangeFinder.Mode(0x0A);
00016     while(1)
00017     {
00018         debugled = !debugled;
00019         RangeFinder.RequestSyncRead();//request a range reading
00020         wait_ms(100);//wait for reading to be prepared
00021         //RangeFinder.Mode(0);//switch to PWM mode
00022         //Computer.printf("PWM reading: %f in | ", Range);
00023         //RangeFinder.Mode(1);//switch to Analog mode
00024         //Computer.printf("Analog reading: %f in | ", Range);
00025         //RangeFinder.Mode(2);//switch to serial mode
00026         Computer.printf("Serial reading: %f in | ", Range);
00027         wait(0.9);
00028     }
00029 }