File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 11#include " Arduino.h"
22#include " mbed.h"
33
4+ using namespace std ::chrono_literals;
5+ using namespace std ::chrono;
6+
47class Tone {
58 mbed::DigitalOut *pin;
69 mbed::Timer timer;
@@ -21,7 +24,7 @@ class Tone {
2124 }
2225
2326 void start (void ) {
24- ticker.attach (mbed::callback (this , &Tone::toggle), 0 . 5f / float ( frequency) );
27+ ticker.attach (mbed::callback (this , &Tone::toggle), 500ms / frequency );
2528 if (duration != 0 ) {
2629 start_timeout ();
2730 }
@@ -37,7 +40,7 @@ class Tone {
3740 }
3841
3942 void start_timeout (void ) {
40- timeout.attach (mbed::callback (this , &Tone::stop), duration/ 1000 . 0f );
43+ timeout.attach (mbed::callback (this , &Tone::stop), duration * 1ms );
4144 }
4245};
4346
Original file line number Diff line number Diff line change @@ -32,19 +32,22 @@ static mbed::LowPowerTimer t;
3232static mbed::Timer t;
3333#endif
3434
35+ using namespace std ::chrono_literals;
36+ using namespace std ::chrono;
37+
3538unsigned long millis ()
3639{
37- return t. read_ms ();
40+ return duration_cast<milliseconds>(t. elapsed_time ()). count ();
3841}
3942
4043unsigned long micros () {
41- return t.read_us ();
44+ return t.elapsed_time (). count ();
4245}
4346
4447void delay (unsigned long ms)
4548{
4649#ifndef NO_RTOS
47- rtos::ThisThread::sleep_for (ms);
50+ rtos::ThisThread::sleep_for (ms * 1ms );
4851#else
4952 wait_us (ms * 1000 );
5053#endif
You can’t perform that action at this time.
0 commit comments