Seongbin Lim
/
sb_first_project
This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.
Diff: main.cpp
- Revision:
- 129:53f2df333d65
- Parent:
- 128:29911670c7fd
- Child:
- 130:d19783810c05
--- a/main.cpp Fri Apr 24 14:54:41 2020 +0000 +++ b/main.cpp Tue Apr 28 08:22:30 2020 +0000 @@ -1,111 +1,40 @@ #include "mbed.h" -PwmOut buzzer(PB_3); +DigitalOut trigger(D3); +DigitalIn echo(D2); +Timer timer1; + +DigitalOut led2(LED2); +Serial pc(PA_2, PA_3, 115200); -void Bell(float freq) { - - buzzer = 1.0 - 0.05; - - int period_us; - period_us = 1000000/freq; - - buzzer.period_us(period_us); -} - -void M_D0(float bt) { - Bell(587.33); - ThisThread::sleep_for(bt*440.0); -} -void E0(float bt) { - Bell(659.26); - ThisThread::sleep_for(bt*440.0); -} -void F0(float bt) { - Bell(698.46); - ThisThread::sleep_for(bt*440.0); -} -void G0(float bt) { - Bell(783.99); - ThisThread::sleep_for(bt*440.0); -} -void M_A0(float bt) { - Bell(880.0); - ThisThread::sleep_for(bt*440.0); -} -void B0(float bt) { - Bell(987.77); - ThisThread::sleep_for(bt*440.0); -} -void C1(float bt) { - Bell(1046.5); - ThisThread::sleep_for(bt*440.0); -} -void M_D1(float bt) { - Bell(1174.66); - ThisThread::sleep_for(bt*440.0); -} -void E1(float bt) { - Bell(1318.51); - ThisThread::sleep_for(bt*440.0); -} -void B(float bt) { - ThisThread::sleep_for(bt*440.0); -} +int main() { + float distance; + + trigger = 0; + pc.printf("\r\nWelcome to Utrasonic Sensor Lab!\r\n");; + + while(1) { + + timer1.reset(); + trigger = 1; + wait_us(10.0); + led2 = 1; + trigger = 0; + + while(echo == 0) {} + timer1.start(); + while(echo == 1) {} + timer1.stop(); + led2 = 0; + distance = timer1.read_us()/58.0; + pc.printf("The distance is %f [cm] \n\r", distance); -int main() { - while(true) { - B(0.5); - E0(0.5); - E0(0.5); - F0(0.5); - G0(1.0); - M_A0(0.5); - B0(0.5); - //--- - M_D1(0.5); - C1(0.5); - C1(0.75); - B0(0.25); - C1(0.5); - G0(1.0); - G0(0.25); - G0(0.25); - // --- - G0(1.0); - M_A0(0.5); - M_A0(2.5); - // --- - G0(0.5); - F0(0.5); - E0(0.5); - M_D0(2.5); - // --- - B(0.5); - E0(0.5); - E0(0.5); - F0(0.5); - G0(0.5); - G0(0.5); - M_A0(0.5); - B0(0.5); - // --- - M_D1(0.5); - C1(0.5); - M_D1(0.5); - E1(2.5); - // --- - B(2.0); - // ---- - B(0.5); - M_D1(1.0); - M_A0(0.5); - C1(1.0); - B0(1.0); - // --- - C1(3.0); - B(4.0); + ThisThread::sleep_for(1000); } + + + return 1; }