yutong look here
Dependencies: FastAnalogIn fastADC
main.cpp@102:14fd65f261a2, 2019-11-25 (annotated)
- Committer:
- candre97
- Date:
- Mon Nov 25 02:25:10 2019 +0000
- Revision:
- 102:14fd65f261a2
- Parent:
- 100:ec006d6f3cb6
- Child:
- 103:2da5fc276330
basic printing from 2 different threads
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 82:abf1b1785bd7 | 1 | /* mbed Microcontroller Library |
mbed_official | 82:abf1b1785bd7 | 2 | * Copyright (c) 2018 ARM Limited |
mbed_official | 82:abf1b1785bd7 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbed_official | 82:abf1b1785bd7 | 4 | */ |
mbed_official | 82:abf1b1785bd7 | 5 | |
Jonathan Austin |
0:2757d7abb7d9 | 6 | #include "mbed.h" |
mbed_official | 100:ec006d6f3cb6 | 7 | #include "platform/mbed_thread.h" |
mbed_official | 82:abf1b1785bd7 | 8 | #include "stats_report.h" |
candre97 | 102:14fd65f261a2 | 9 | #include <AnalogIn.h> |
candre97 | 102:14fd65f261a2 | 10 | #include <AnalogOut.h> |
Jonathan Austin |
0:2757d7abb7d9 | 11 | |
candre97 | 102:14fd65f261a2 | 12 | AnalogOut v_src(GPIO0); |
candre97 | 102:14fd65f261a2 | 13 | AnalogIn therm(GPIO2); |
Jonathan Austin |
0:2757d7abb7d9 | 14 | |
mbed_official | 88:bea4f2daa48c | 15 | #define SLEEP_TIME 500 // (msec) |
mbed_official | 88:bea4f2daa48c | 16 | #define PRINT_AFTER_N_LOOPS 20 |
mbed_official | 88:bea4f2daa48c | 17 | |
candre97 | 102:14fd65f261a2 | 18 | #include "mbed.h" |
candre97 | 102:14fd65f261a2 | 19 | |
candre97 | 102:14fd65f261a2 | 20 | DigitalOut led1(LED1); |
candre97 | 102:14fd65f261a2 | 21 | DigitalOut led2(LED2); |
candre97 | 102:14fd65f261a2 | 22 | Thread thread1; |
candre97 | 102:14fd65f261a2 | 23 | Thread thread2; |
candre97 | 102:14fd65f261a2 | 24 | |
candre97 | 102:14fd65f261a2 | 25 | void led1_thread() { |
Jonathan Austin |
0:2757d7abb7d9 | 26 | while (true) { |
Jonathan Austin |
0:2757d7abb7d9 | 27 | led1 = !led1; |
candre97 | 102:14fd65f261a2 | 28 | wait(0.5); |
candre97 | 102:14fd65f261a2 | 29 | printf("Printing from thread #%d", 1); |
Jonathan Austin |
0:2757d7abb7d9 | 30 | } |
Jonathan Austin |
0:2757d7abb7d9 | 31 | } |
candre97 | 102:14fd65f261a2 | 32 | |
candre97 | 102:14fd65f261a2 | 33 | void led2_thread() { |
candre97 | 102:14fd65f261a2 | 34 | while (true) { |
candre97 | 102:14fd65f261a2 | 35 | led2 = !led2; |
candre97 | 102:14fd65f261a2 | 36 | wait(1); |
candre97 | 102:14fd65f261a2 | 37 | printf("Printing from thread #%d", 2); |
candre97 | 102:14fd65f261a2 | 38 | } |
candre97 | 102:14fd65f261a2 | 39 | } |
candre97 | 102:14fd65f261a2 | 40 | |
candre97 | 102:14fd65f261a2 | 41 | int main() { |
candre97 | 102:14fd65f261a2 | 42 | thread1.start(led1_thread); |
candre97 | 102:14fd65f261a2 | 43 | thread2.start(led2_thread); |
candre97 | 102:14fd65f261a2 | 44 | } |