Created libraries2
Dependencies: mbed ultrasonic
main.cpp@3:b6f543e4508a, 2015-03-10 (annotated)
- Committer:
- hebryn
- Date:
- Tue Mar 10 15:24:01 2015 +0000
- Revision:
- 3:b6f543e4508a
- Parent:
- 2:8938c73c2aa8
- Child:
- 4:ae7f8a25c748
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
VegardMidt | 0:017111c9207d | 1 | #include "mbed.h" |
VegardMidt | 0:017111c9207d | 2 | #include "ultrasonic.h" |
hebryn | 1:21587a66f911 | 3 | |
hebryn | 1:21587a66f911 | 4 | PwmOut TX(D9); |
hebryn | 3:b6f543e4508a | 5 | InterruptIn irq(D8); |
hebryn | 3:b6f543e4508a | 6 | Timer t1; |
hebryn | 3:b6f543e4508a | 7 | Timeout to; |
hebryn | 3:b6f543e4508a | 8 | Serial pc(SERIAL_TX, SERIAL_RX); |
hebryn | 1:21587a66f911 | 9 | |
hebryn | 3:b6f543e4508a | 10 | void TX_send(){ |
hebryn | 3:b6f543e4508a | 11 | t1.reset(); |
hebryn | 3:b6f543e4508a | 12 | TX.write(0.5); |
hebryn | 3:b6f543e4508a | 13 | wait_us(125); |
hebryn | 3:b6f543e4508a | 14 | TX = 0; |
hebryn | 3:b6f543e4508a | 15 | to.attach(TX_send,1); |
hebryn | 3:b6f543e4508a | 16 | } |
hebryn | 3:b6f543e4508a | 17 | |
hebryn | 3:b6f543e4508a | 18 | void get_dist(){ |
hebryn | 3:b6f543e4508a | 19 | int dist = t1.read_us(); |
hebryn | 3:b6f543e4508a | 20 | pc.printf("time = %d", dist); |
hebryn | 3:b6f543e4508a | 21 | } |
hebryn | 3:b6f543e4508a | 22 | |
hebryn | 1:21587a66f911 | 23 | int main() { |
hebryn | 3:b6f543e4508a | 24 | t1.start(); |
hebryn | 1:21587a66f911 | 25 | TX.period_us(25); |
hebryn | 3:b6f543e4508a | 26 | TX_send(); |
hebryn | 3:b6f543e4508a | 27 | while(1){ |
hebryn | 3:b6f543e4508a | 28 | irq.rise(&get_dist); |
hebryn | 3:b6f543e4508a | 29 | } |
hebryn | 3:b6f543e4508a | 30 | |
hebryn | 1:21587a66f911 | 31 | } |