hallo,
danke, den 1. Teil mache und teste ich sofort!
auf der anderen Seite sollten gerade die Threads ihren momentanen Status per Serial an die Konsole melden, damit man den augenblicklichen Status erkenn kann, so ähnlich wie bei fprintf(stderr, ...) auf meinem Pi ...
- - - Aktualisiert - - -
update:
Code geändert:
Code:#include <Arduino.h> #include <thread> #include <chrono> #ifndef LED_BUILTIN #define LED_BUILTIN 13 #endif const auto one_sec = std::chrono::seconds { 1 }; void counter_loop() { static uint32_t counter = 0; while(true) { Serial.print("counter_loop: "); Serial.println(counter); std::this_thread::sleep_for(one_sec); } } void blinker_loop() { static uint32_t counter = 0; while(true) { digitalWrite(LED_BUILTIN, HIGH); Serial.print("blinker_loop (HIGH) counter: "); Serial.println(counter); std::this_thread::sleep_for(one_sec); digitalWrite(LED_BUILTIN, LOW); Serial.print("blinker_loop (LOW) counter: "); Serial.println(counter); std::this_thread::sleep_for(one_sec); } } std::thread counter_loop_thread(counter_loop); std::thread blinker_loop_thread(blinker_loop); void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT); } uint32_t main_loop_counter = 0; void loop() { main_loop_counter++; Serial.print("main loop: "); Serial.println(main_loop_counter); delay(10000); }
Good news: es läuft (irgendwie),
und die LED blinkt auch!
A-Bär:
Trotz "static" in den threads zählen aber die counter dort nicht hoch:
main loop: 1
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
main loop: 2
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
main loop: 3
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
counter_loop: 0
blinker_loop (LOW) counter: 0
blinker_loop (HIGH) counter: 0
counter_loop: 0
main loop: 4
Lesezeichen