Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed DS18B20 TextLCD
Diff: main.cpp
- Revision:
- 1:f8a4796e766e
- Parent:
- 0:55c37ea095b0
diff -r 55c37ea095b0 -r f8a4796e766e main.cpp
--- a/main.cpp Thu Feb 13 16:27:38 2020 +0000
+++ b/main.cpp Thu Feb 13 17:30:24 2020 +0000
@@ -10,6 +10,8 @@
#include <limits>
#include <flash.h>
#include <cassert>
+#include <cmath>
+extern "C" long int lroundf(float x);
static DigitalOut led_on_board(PC_13);
@@ -277,9 +279,8 @@
static void setup() {
// wait for voltage stability
- wait(1);
+ // wait(0.1);
// some info
- lcd_cls();
lcd_println("Hello!");
lcd_println("clock=%ld", SystemCoreClock);
wait(1);
@@ -298,25 +299,26 @@
lcd_cls();
char temperature_s[8] = "ERROR";
- if (ds18b20_err == 0) {
- const int temperature_dC = temperature_f_C * 10;
- const int temperature_C = temperature_f_C;
-
- if (temperature_C < -100 || temperature_C > 100) {
+ if (ds18b20_err == 0) {
+ if (temperature_f_C < -100 || temperature_f_C > 100) {
snprintf(temperature_s, sizeof(temperature_s), "INVAL");
} else {
if (!output ^ state.inverted) {
- if (temperature_C > state.high) {
+ if (temperature_f_C > state.high) {
output = 1 ^ state.inverted;
}
} else {
- if (temperature_C < state.low) {
+ if (temperature_f_C < state.low) {
output = 0 ^ state.inverted;
}
}
- snprintf(temperature_s, sizeof(temperature_s), "%3d.%d'C", temperature_C, temperature_dC % 10);
+ const long temperature_dC = lroundf(temperature_f_C * 10);
+ snprintf(temperature_s, sizeof(temperature_s),
+ "%3ld.%ld'C",
+ temperature_dC / 10,
+ temperature_dC % 10);
}
}