Jim Belesiu
/
SonarRangeFinderV1
MB7040 Range finder experiment.
Revision 2:6daf72c57cee, committed 2015-01-11
- Comitter:
- Belesiu
- Date:
- Sun Jan 11 23:10:16 2015 +0000
- Parent:
- 1:0cf1f2254f10
- Commit message:
- Test program to check DAC output given a fixed input range.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 0cf1f2254f10 -r 6daf72c57cee main.cpp --- a/main.cpp Sat Jan 03 22:40:31 2015 +0000 +++ b/main.cpp Sun Jan 11 23:10:16 2015 +0000 @@ -15,11 +15,15 @@ char range_read[2]; float range; +#define N 8 +float test_range[N] = {26.0, 100.0, 200.0, 300.0, 400.0,500.0, 600.0, 765.0}; + AnalogOut signal(p18); int main() { int x = 0; + int i = 0; while(1) { @@ -28,27 +32,21 @@ wait(0.2); myled = 0; wait(0.2); - // pc.printf("Hello Jim! - %d\n", x++); - - // For MB7040 + // pc.printf("Canned test program! - %d: ", x++); - config_r[0] = 0x00; // set pointer reg to ‘cmd register' - config_r[1] = 0x51; // config data byte1 - rangefinder.write(addr, config_r, 2); - wait(0.07); + range = test_range[i]; - config_r[0] = 0x02; //set pointer reg to 'data register' - rangefinder.write(addr, config_r, 1); //send to pointer 'read range' - rangefinder.read(addr, range_read, 2); //read the two-byte range data - range = ((range_read[0] << 8) + range_read[1]); - - pc.printf("%d Range = %.2f cm\n\r", x++, range); //print range on screen + pc.printf("%d Range = %.2f cm", x++, range); //print range on screen wait(0.05); // Output voltage proportional to distance. // The output value for the variable signal is 0 to 1.0. signal = range / 765.0; + + pc.printf(" Signal[%d] = %.2f \n\r", i, range / 765.0); + wait(2.0); + if(++i == N) i = 0; } }