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.
main.cpp@40:04a05851ae7b, 2017-03-17 (annotated)
- Committer:
- NKarandey
- Date:
- Fri Mar 17 22:19:09 2017 +0000
- Revision:
- 40:04a05851ae7b
- Parent:
- 39:ae41a212c170
- Child:
- 41:d52445129908
Improve argument type in playTune
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| NKarandey | 40:04a05851ae7b | 1 | #include "mbed.h" |
| NKarandey | 40:04a05851ae7b | 2 | #include "rtos.h" |
| NKarandey | 40:04a05851ae7b | 3 | |
| NKarandey | 40:04a05851ae7b | 4 | // Thread thread; |
| NKarandey | 40:04a05851ae7b | 5 | // |
| NKarandey | 40:04a05851ae7b | 6 | // volatile int counter = 0; |
| NKarandey | 40:04a05851ae7b | 7 | // |
| NKarandey | 40:04a05851ae7b | 8 | // void serialThread() { |
| NKarandey | 40:04a05851ae7b | 9 | // while(true) { |
| NKarandey | 40:04a05851ae7b | 10 | // // printf("Hey\n"); |
| NKarandey | 40:04a05851ae7b | 11 | // counter++; |
| NKarandey | 40:04a05851ae7b | 12 | // Thread::wait(1000); |
| NKarandey | 40:04a05851ae7b | 13 | // } |
| NKarandey | 40:04a05851ae7b | 14 | // } |
| NKarandey | 40:04a05851ae7b | 15 | // |
| NKarandey | 40:04a05851ae7b | 16 | // int main() { |
| NKarandey | 40:04a05851ae7b | 17 | // printf("Hello\n\r"); |
| NKarandey | 40:04a05851ae7b | 18 | // thread.start(&serialThread); |
| NKarandey | 40:04a05851ae7b | 19 | // |
| NKarandey | 40:04a05851ae7b | 20 | // while(true) { |
| NKarandey | 40:04a05851ae7b | 21 | // printf("%d\n\r", counter); |
| NKarandey | 40:04a05851ae7b | 22 | // Thread::wait(500); |
| NKarandey | 40:04a05851ae7b | 23 | // wait(5); |
| NKarandey | 40:04a05851ae7b | 24 | // } |
| NKarandey | 40:04a05851ae7b | 25 | // |
| NKarandey | 40:04a05851ae7b | 26 | // return 0; |
| NKarandey | 40:04a05851ae7b | 27 | // } |
| NKarandey | 40:04a05851ae7b | 28 | // #include "mbed.h" |
| NKarandey | 40:04a05851ae7b | 29 | // #include "rtos.h" |
| NKarandey | 40:04a05851ae7b | 30 | |
| NKarandey | 40:04a05851ae7b | 31 | Mutex stdio_mutex; |
| NKarandey | 40:04a05851ae7b | 32 | |
| NKarandey | 40:04a05851ae7b | 33 | void notify(const char* name, int state) { |
| NKarandey | 40:04a05851ae7b | 34 | stdio_mutex.lock(); |
| NKarandey | 40:04a05851ae7b | 35 | printf("%s: %d\n\r", name, state); |
| NKarandey | 40:04a05851ae7b | 36 | stdio_mutex.unlock(); |
| NKarandey | 40:04a05851ae7b | 37 | } |
| NKarandey | 40:04a05851ae7b | 38 | |
| NKarandey | 40:04a05851ae7b | 39 | void test_thread(void const *args) { |
| NKarandey | 40:04a05851ae7b | 40 | while (true) { |
| NKarandey | 40:04a05851ae7b | 41 | notify((const char*)args, 0); Thread::wait(1000); |
| NKarandey | 40:04a05851ae7b | 42 | notify((const char*)args, 1); Thread::wait(1000); |
| NKarandey | 40:04a05851ae7b | 43 | } |
| NKarandey | 40:04a05851ae7b | 44 | } |
| NKarandey | 40:04a05851ae7b | 45 | |
| NKarandey | 40:04a05851ae7b | 46 | int main() { |
| NKarandey | 40:04a05851ae7b | 47 | Thread t2; |
| NKarandey | 40:04a05851ae7b | 48 | Thread t3; |
| NKarandey | 40:04a05851ae7b | 49 | |
| NKarandey | 40:04a05851ae7b | 50 | t2.start(callback(test_thread, (void *)"Th 2")); |
| NKarandey | 40:04a05851ae7b | 51 | t3.start(callback(test_thread, (void *)"Th 3")); |
| NKarandey | 40:04a05851ae7b | 52 | |
| NKarandey | 40:04a05851ae7b | 53 | test_thread((void *)"Th 1"); |
| NKarandey | 40:04a05851ae7b | 54 | } |
