Ferrograph
New member
When I use Serial.printf in a thread, it appears to work once - I see the message in the serial monitor. Main loop appears to be running (LED flash and Loop message). But the thread is either hung or crashed. Possibly this is thread safety issue. How can I use Serial.printf() in a thread? See code below.
C++:
#include <TeensyThreads.h>
#include <_Teensy.h>
// IO Pins
const int ledPin = 13;
// the setup function runs once when you press reset or power the board
void setup() {
// Setup debug serial
Serial.begin(115200);
while (!Serial) { delay(100); }
Serial.println("~ Welcome to Threaded Project ~");
pinMode(ledPin, OUTPUT);
delay(2000);
int id = threads.addThread(UpdateDisplay);
}
// the loop function runs over and over again until power down or reset
void loop() {
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000);
Serial.println("End of Loop.");// wait for a second
}
void UpdateDisplay()
{
int progress = 0;
while (1)
{
delay(200);
progress++;
if (progress > 100) progress = 1;
Serial.printf("Progress: %d \n", progress);
}
}