yutong look here
Dependencies: FastAnalogIn fastADC
Diff: main.cpp
- Revision:
- 102:14fd65f261a2
- Parent:
- 100:ec006d6f3cb6
- Child:
- 103:2da5fc276330
--- a/main.cpp Wed Oct 23 18:00:04 2019 +0100 +++ b/main.cpp Mon Nov 25 02:25:10 2019 +0000 @@ -6,28 +6,39 @@ #include "mbed.h" #include "platform/mbed_thread.h" #include "stats_report.h" +#include <AnalogIn.h> +#include <AnalogOut.h> -DigitalOut led1(LED1); +AnalogOut v_src(GPIO0); +AnalogIn therm(GPIO2); #define SLEEP_TIME 500 // (msec) #define PRINT_AFTER_N_LOOPS 20 -// main() runs in its own thread in the OS -int main() -{ - SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */); - - int count = 0; +#include "mbed.h" + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +Thread thread1; +Thread thread2; + +void led1_thread() { while (true) { - // Blink LED and wait 0.5 seconds led1 = !led1; - thread_sleep_for(SLEEP_TIME); - - if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { - // Following the main thread wait, report on the current system status - sys_state.report_state(); - count = 0; - } - ++count; + wait(0.5); + printf("Printing from thread #%d", 1); } } + +void led2_thread() { + while (true) { + led2 = !led2; + wait(1); + printf("Printing from thread #%d", 2); + } +} + +int main() { + thread1.start(led1_thread); + thread2.start(led2_thread); +} \ No newline at end of file