Created libraries2

Dependencies:   mbed ultrasonic

Committer:
VegardMidt
Date:
Thu Apr 16 08:54:29 2015 +0000
Revision:
4:ae7f8a25c748
Parent:
3:b6f543e4508a
Child:
5:b2df25183cb1
Tx1, Tx2, HVoff, signal in

Who changed what in which revision?

UserRevisionLine numberNew contents of line
VegardMidt 0:017111c9207d 1 #include "mbed.h"
VegardMidt 0:017111c9207d 2 #include "ultrasonic.h"
hebryn 1:21587a66f911 3
VegardMidt 4:ae7f8a25c748 4 PwmOut TX1(D9); // Use pin D9
VegardMidt 4:ae7f8a25c748 5 DigitalOut TX2(D8); // Use pin D8
VegardMidt 4:ae7f8a25c748 6 DigitalOut HVoff(D6); // Use pin D6
VegardMidt 4:ae7f8a25c748 7 InterruptIn signal(D7); // Use pin D7
VegardMidt 4:ae7f8a25c748 8 //DigitalOut tresh(D7);
VegardMidt 4:ae7f8a25c748 9 Timeout to1;
hebryn 3:b6f543e4508a 10 Timer t1;
hebryn 3:b6f543e4508a 11 Serial pc(SERIAL_TX, SERIAL_RX);
hebryn 1:21587a66f911 12
VegardMidt 4:ae7f8a25c748 13 void TX1_send(){
VegardMidt 4:ae7f8a25c748 14 HVoff = 0;
VegardMidt 4:ae7f8a25c748 15 //tresh = 1;
VegardMidt 4:ae7f8a25c748 16 t1.reset();
VegardMidt 4:ae7f8a25c748 17 TX1.period(0.0000252); // Set the period of TX1 to 25.2us (39,682kHz)
VegardMidt 4:ae7f8a25c748 18 TX1.pulsewidth(0.0000116); // Set the pulsewidth of TX1 to 11.6us (ON)
VegardMidt 4:ae7f8a25c748 19 wait(0.0002016); // Waits 201.6us
VegardMidt 4:ae7f8a25c748 20 TX1 = 0;
VegardMidt 4:ae7f8a25c748 21 //tresh =0;
VegardMidt 4:ae7f8a25c748 22 HVoff = 1;
VegardMidt 4:ae7f8a25c748 23 //pc.printf("It writes TX1\r\n");
VegardMidt 4:ae7f8a25c748 24 to1.attach(TX1_send,0.01); // Sends for 1000us
VegardMidt 4:ae7f8a25c748 25 wait_ms(86); // Waits 86ms. Total 100ms
hebryn 3:b6f543e4508a 26 }
hebryn 3:b6f543e4508a 27
VegardMidt 4:ae7f8a25c748 28
VegardMidt 4:ae7f8a25c748 29 void signal_reciev(){
VegardMidt 4:ae7f8a25c748 30
VegardMidt 4:ae7f8a25c748 31 pc.printf("test1");
VegardMidt 4:ae7f8a25c748 32
VegardMidt 4:ae7f8a25c748 33 float time = t1.read();
VegardMidt 4:ae7f8a25c748 34
VegardMidt 4:ae7f8a25c748 35 pc.printf("%f/r/n", time);
VegardMidt 4:ae7f8a25c748 36
hebryn 3:b6f543e4508a 37 }
VegardMidt 4:ae7f8a25c748 38
hebryn 1:21587a66f911 39 int main() {
VegardMidt 4:ae7f8a25c748 40 TX2 = 1;
VegardMidt 4:ae7f8a25c748 41 TX1_send();
VegardMidt 4:ae7f8a25c748 42 signal.rise(&signal_reciev);
VegardMidt 4:ae7f8a25c748 43 //pc.printf("%f\r\n", volt.read()); // Function to write to serial chart
VegardMidt 4:ae7f8a25c748 44 while(1);
VegardMidt 4:ae7f8a25c748 45 }