Ultrasonic distance meter mede with micro:bit and Grove Inventor Kit
Dependencies: DigitDisplay RangeFinder microbit
Fork of microbit-component-display by
main.cpp@1:ed667cae3667, 2017-08-24 (annotated)
- Committer:
- ytsuboi
- Date:
- Thu Aug 24 09:05:15 2017 +0000
- Revision:
- 1:ed667cae3667
- Parent:
- 0:0c37474c8541
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JonnyA | 0:0c37474c8541 | 1 | #include "MicroBit.h" |
ytsuboi | 1:ed667cae3667 | 2 | #include "DigitDisplay.h" |
ytsuboi | 1:ed667cae3667 | 3 | #include "RangeFinder.h" |
JonnyA | 0:0c37474c8541 | 4 | |
JonnyA | 0:0c37474c8541 | 5 | MicroBitDisplay display; |
ytsuboi | 1:ed667cae3667 | 6 | //DigitDisplay digit(P0_3, P0_22); // P0/P14 |
ytsuboi | 1:ed667cae3667 | 7 | DigitDisplay digit(P0_2, P0_21); // P1/P15 |
ytsuboi | 1:ed667cae3667 | 8 | |
ytsuboi | 1:ed667cae3667 | 9 | RangeFinder rf(P0_3, 10, 5800.0, 100000); |
JonnyA | 0:0c37474c8541 | 10 | |
JonnyA | 0:0c37474c8541 | 11 | int main() |
JonnyA | 0:0c37474c8541 | 12 | { |
ytsuboi | 1:ed667cae3667 | 13 | float d; |
ytsuboi | 1:ed667cae3667 | 14 | |
ytsuboi | 1:ed667cae3667 | 15 | while(1) { |
ytsuboi | 1:ed667cae3667 | 16 | d = rf.read_m() * 100; |
ytsuboi | 1:ed667cae3667 | 17 | digit.write(0,(int)d / 1000 % 10); |
ytsuboi | 1:ed667cae3667 | 18 | digit.write(1,(int)d / 100 % 10); |
ytsuboi | 1:ed667cae3667 | 19 | digit.write(2,(int)d / 10 % 10); |
ytsuboi | 1:ed667cae3667 | 20 | digit.write(3,(int)d / 1 % 10); |
ytsuboi | 1:ed667cae3667 | 21 | wait(1); |
ytsuboi | 1:ed667cae3667 | 22 | } |
JonnyA | 0:0c37474c8541 | 23 | } |