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 1
1
#include " Arduino.h"
2
2
#include " mbed.h"
3
3
4
+ using namespace std ::chrono_literals;
5
+ using namespace std ::chrono;
6
+
4
7
class Tone {
5
8
mbed::DigitalOut *pin;
6
9
mbed::Timer timer;
@@ -21,7 +24,7 @@ class Tone {
21
24
}
22
25
23
26
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 );
25
28
if (duration != 0 ) {
26
29
start_timeout ();
27
30
}
@@ -37,7 +40,7 @@ class Tone {
37
40
}
38
41
39
42
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 );
41
44
}
42
45
};
43
46
Original file line number Diff line number Diff line change @@ -32,19 +32,22 @@ static mbed::LowPowerTimer t;
32
32
static mbed::Timer t;
33
33
#endif
34
34
35
+ using namespace std ::chrono_literals;
36
+ using namespace std ::chrono;
37
+
35
38
unsigned long millis ()
36
39
{
37
- return t. read_ms ();
40
+ return duration_cast<milliseconds>(t. elapsed_time ()). count ();
38
41
}
39
42
40
43
unsigned long micros () {
41
- return t.read_us ();
44
+ return t.elapsed_time (). count ();
42
45
}
43
46
44
47
void delay (unsigned long ms)
45
48
{
46
49
#ifndef NO_RTOS
47
- rtos::ThisThread::sleep_for (ms);
50
+ rtos::ThisThread::sleep_for (ms * 1ms );
48
51
#else
49
52
wait_us (ms * 1000 );
50
53
#endif
You can’t perform that action at this time.
0 commit comments