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.
Fork of mbed-os-example-mbed5-blinky by
main.cpp@20:34e8d1b03de2, 2016-11-04 (annotated)
- Committer:
- Roietronics
- Date:
- Fri Nov 04 00:29:32 2016 +0000
- Revision:
- 20:34e8d1b03de2
- Parent:
- 19:1c65f0106b2c
switch to none callback version
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Jonathan Austin |
0:2757d7abb7d9 | 1 | #include "mbed.h" |
| Roietronics | 17:267747192719 | 2 | #include "Thread.h" |
| Roietronics | 18:7f2d0c1cfb33 | 3 | #include "Callback.h" |
| Jonathan Austin |
0:2757d7abb7d9 | 4 | |
| Jonathan Austin |
0:2757d7abb7d9 | 5 | DigitalOut led1(LED1); |
| Jonathan Austin |
0:2757d7abb7d9 | 6 | |
| Roietronics | 17:267747192719 | 7 | #define mySignal 0x01 |
| Roietronics | 18:7f2d0c1cfb33 | 8 | class MyTest |
| Roietronics | 17:267747192719 | 9 | { |
| Roietronics | 17:267747192719 | 10 | public: |
| Roietronics | 17:267747192719 | 11 | osThreadId _id; |
| Roietronics | 17:267747192719 | 12 | Thread _thread; |
| Roietronics | 17:267747192719 | 13 | |
| Roietronics | 18:7f2d0c1cfb33 | 14 | void myWorker(void const* arge) |
| Roietronics | 17:267747192719 | 15 | { |
| Roietronics | 18:7f2d0c1cfb33 | 16 | MyTest* t = (MyTest*)arge; |
| Roietronics | 17:267747192719 | 17 | int i; |
| Roietronics | 17:267747192719 | 18 | i++; |
| Roietronics | 19:1c65f0106b2c | 19 | osSignalSet(t->_id, mySignal); |
| Roietronics | 19:1c65f0106b2c | 20 | } |
| Roietronics | 17:267747192719 | 21 | |
| Roietronics | 18:7f2d0c1cfb33 | 22 | MyTest(osThreadId id) : |
| Roietronics | 17:267747192719 | 23 | _id(id), |
| Roietronics | 17:267747192719 | 24 | _thread() |
| Roietronics | 17:267747192719 | 25 | { |
| Roietronics | 20:34e8d1b03de2 | 26 | osStatus status = _thread.start(this, &MyTest::myWorker); |
| Roietronics | 20:34e8d1b03de2 | 27 | // osStatus status = _thread.start(mbed::Callback<void()>((MyTest*)this, &MyTest::myWorker)); |
| Roietronics | 17:267747192719 | 28 | } |
| Roietronics | 17:267747192719 | 29 | |
| Roietronics | 17:267747192719 | 30 | }; |
| Roietronics | 17:267747192719 | 31 | |
| Jonathan Austin |
1:846c97078558 | 32 | // main() runs in its own thread in the OS |
| Jonathan Austin |
1:846c97078558 | 33 | // (note the calls to Thread::wait below for delays) |
| Jonathan Austin |
0:2757d7abb7d9 | 34 | int main() { |
| Roietronics | 17:267747192719 | 35 | osThreadId id = Thread::gettid(); |
| Roietronics | 18:7f2d0c1cfb33 | 36 | MyTest* test = new MyTest(id); |
| Jonathan Austin |
0:2757d7abb7d9 | 37 | while (true) { |
| Jonathan Austin |
0:2757d7abb7d9 | 38 | led1 = !led1; |
| Jonathan Austin |
0:2757d7abb7d9 | 39 | Thread::wait(500); |
| Jonathan Austin |
0:2757d7abb7d9 | 40 | } |
| Jonathan Austin |
0:2757d7abb7d9 | 41 | } |
| Jonathan Austin |
1:846c97078558 | 42 |
