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.
main.cpp@4:a615b75d4126, 2010-08-28 (annotated)
- Committer:
- Blaze513
- Date:
- Sat Aug 28 07:59:29 2010 +0000
- Revision:
- 4:a615b75d4126
- Parent:
- 1:b533b95e807a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Blaze513 | 4:a615b75d4126 | 1 | #include "mbed.h" |
Blaze513 | 4:a615b75d4126 | 2 | #include "MB1210.h" |
Blaze513 | 4:a615b75d4126 | 3 | |
Blaze513 | 4:a615b75d4126 | 4 | DigitalOut debugled(LED1); |
Blaze513 | 4:a615b75d4126 | 5 | Serial Computer(USBTX, USBRX); |
Blaze513 | 4:a615b75d4126 | 6 | |
Blaze513 | 4:a615b75d4126 | 7 | MB1210 RangeFinder(p12, p15, p13, p14); |
Blaze513 | 4:a615b75d4126 | 8 | float Range; |
Blaze513 | 4:a615b75d4126 | 9 | int main() |
Blaze513 | 4:a615b75d4126 | 10 | { |
Blaze513 | 4:a615b75d4126 | 11 | Computer.baud(9600); |
Blaze513 | 4:a615b75d4126 | 12 | debugled = 0; |
Blaze513 | 4:a615b75d4126 | 13 | RangeFinder.Unit(39.370);//change units to inches |
Blaze513 | 4:a615b75d4126 | 14 | RangeFinder.AttachInterruptBuffer(&Range); |
Blaze513 | 4:a615b75d4126 | 15 | RangeFinder.Mode(0x0A); |
Blaze513 | 4:a615b75d4126 | 16 | while(1) |
Blaze513 | 4:a615b75d4126 | 17 | { |
Blaze513 | 4:a615b75d4126 | 18 | debugled = !debugled; |
Blaze513 | 4:a615b75d4126 | 19 | RangeFinder.RequestSyncRead();//request a range reading |
Blaze513 | 4:a615b75d4126 | 20 | wait_ms(100);//wait for reading to be prepared |
Blaze513 | 4:a615b75d4126 | 21 | //RangeFinder.Mode(0);//switch to PWM mode |
Blaze513 | 4:a615b75d4126 | 22 | //Computer.printf("PWM reading: %f in | ", Range); |
Blaze513 | 4:a615b75d4126 | 23 | //RangeFinder.Mode(1);//switch to Analog mode |
Blaze513 | 4:a615b75d4126 | 24 | //Computer.printf("Analog reading: %f in | ", Range); |
Blaze513 | 4:a615b75d4126 | 25 | //RangeFinder.Mode(2);//switch to serial mode |
Blaze513 | 4:a615b75d4126 | 26 | Computer.printf("Serial reading: %f in | ", Range); |
Blaze513 | 4:a615b75d4126 | 27 | wait(0.9); |
Blaze513 | 4:a615b75d4126 | 28 | } |
Blaze513 | 0:3d969e0b4ca0 | 29 | } |