Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Tune.cpp
- Revision:
- 0:2fc1a329e9a1
diff -r 000000000000 -r 2fc1a329e9a1 Tune.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tune.cpp Thu Dec 09 15:51:58 2021 +0000 @@ -0,0 +1,45 @@ +#include "Tune.h" + +InterruptIn button(D2); +PwmOut buzzer(D14); +Timer debounce; +Ticker flipper; + +int svira=1; +float frequency[]= {82.41, 110.00, 146.83, 196.00, 246.94, 329.63}; + +void TuneInit() +{ + debounce.start(); + button.rise(&toggle); + flipper.attach(&piezo, 2); +} + +void toggle() +{ + if (debounce.read_ms()>200) { + inkrementatitator(); + } + debounce.reset(); +} + +void inkrementatitator() +{ + if(i==5) { + i=0; + } else { + i++; + } +} + +void piezo() +{ + if(svira==1) { + svira=0; + buzzer.period(1/((frequency[i])*2)); + buzzer=0.5; + } else { + buzzer=0; + svira=1; + } +}