asdca
Dependencies: mbed
main.cpp@0:6d03232fcb64, 2018-04-29 (annotated)
- Committer:
- baumamer
- Date:
- Sun Apr 29 12:13:41 2018 +0000
- Revision:
- 0:6d03232fcb64
rfd777402
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
baumamer | 0:6d03232fcb64 | 1 | #include "mbed.h" |
baumamer | 0:6d03232fcb64 | 2 | #include "RFD77402.h" |
baumamer | 0:6d03232fcb64 | 3 | |
baumamer | 0:6d03232fcb64 | 4 | |
baumamer | 0:6d03232fcb64 | 5 | I2C i2c(PB_9, PB_8); |
baumamer | 0:6d03232fcb64 | 6 | |
baumamer | 0:6d03232fcb64 | 7 | uint16_t distance; |
baumamer | 0:6d03232fcb64 | 8 | uint16_t confidence_value; |
baumamer | 0:6d03232fcb64 | 9 | uint8_t valid_pixles; |
baumamer | 0:6d03232fcb64 | 10 | |
baumamer | 0:6d03232fcb64 | 11 | uint8_t error_code; |
baumamer | 0:6d03232fcb64 | 12 | |
baumamer | 0:6d03232fcb64 | 13 | int main() |
baumamer | 0:6d03232fcb64 | 14 | { |
baumamer | 0:6d03232fcb64 | 15 | |
baumamer | 0:6d03232fcb64 | 16 | printf("i2c created \n\r"); |
baumamer | 0:6d03232fcb64 | 17 | RFD77402 sensor(&i2c); |
baumamer | 0:6d03232fcb64 | 18 | printf("sensor created \n\r"); |
baumamer | 0:6d03232fcb64 | 19 | if (sensor.init()) printf ("init success \n\n\r"); |
baumamer | 0:6d03232fcb64 | 20 | else printf("init fail \n\r"); |
baumamer | 0:6d03232fcb64 | 21 | |
baumamer | 0:6d03232fcb64 | 22 | for (uint8_t x = 0 ; x < 100 ; x++) { |
baumamer | 0:6d03232fcb64 | 23 | error_code = sensor.takeMeasurement(); |
baumamer | 0:6d03232fcb64 | 24 | if (error_code) |
baumamer | 0:6d03232fcb64 | 25 | { |
baumamer | 0:6d03232fcb64 | 26 | printf("error %d\n\r", error_code); |
baumamer | 0:6d03232fcb64 | 27 | } |
baumamer | 0:6d03232fcb64 | 28 | else |
baumamer | 0:6d03232fcb64 | 29 | { |
baumamer | 0:6d03232fcb64 | 30 | distance = sensor.getDistance(); |
baumamer | 0:6d03232fcb64 | 31 | confidence_value = sensor.getConfidenceValue(); |
baumamer | 0:6d03232fcb64 | 32 | valid_pixles = sensor.getValidPixels(); |
baumamer | 0:6d03232fcb64 | 33 | |
baumamer | 0:6d03232fcb64 | 34 | printf("distance = %d mm\t confidence = %d\t valid pixels: %d\n\r", distance, confidence_value, valid_pixles); |
baumamer | 0:6d03232fcb64 | 35 | } |
baumamer | 0:6d03232fcb64 | 36 | wait(0.5); |
baumamer | 0:6d03232fcb64 | 37 | } |
baumamer | 0:6d03232fcb64 | 38 | } |