Skip to content

Commit 46ef751

Browse files
committedJun 12, 2024
Fix output function in printf().
1 parent a9da492 commit 46ef751

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
 

‎Printf.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ int printf(const char* fmt, ...) {
1515
va_end(arg_ptr);
1616

1717
// output to the serial console through the 'Serial'
18-
#if 1
18+
#if defined(ARDUINO_UNOR4_MINIMA)
19+
1920
len = Serial.write((uint8_t*)buf, (size_t)len);
20-
#else
21+
22+
#else // ARDUINO_UNOR4_WIFI
23+
2124
len = Serial.print(buf);
22-
#endif
2325

24-
#if defined(ARDUINO_UNOWIFIR4) && 1
25-
delay(2); // UNO R4 WiFi needs some delay to fix buffer overrun
2626
#endif
2727

2828
return len;

‎examples/printf/printf.ino

+9
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ void setup() {
99
Serial.begin(9600);
1010
while (!Serial);
1111

12+
#ifdef ARDUINO_UNOR4_WIFI
13+
// UNO R4 WiFi needs to wait for a while to complete Serial initialization.
14+
delay(1000); // It requires at least 600 ms.
15+
#endif
16+
17+
u_int32_t t = micros();
18+
1219
#define EPSILON 0.00001
1320

1421
for (float f = 0.0; f <= 1.0 + EPSILON; f += 0.01) {
1522
printf("f = %5.3f\n", f);
1623
printf("e = %5.3e\n", f);
1724
}
25+
26+
Serial.println(micros() - t);
1827
}
1928

2029
void loop() {

0 commit comments

Comments
 (0)
Please sign in to comment.