From 63146c96c4af9f5e7bd462e2f4e958af217b3035 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Thu, 11 Aug 2022 15:40:31 +0100 Subject: [PATCH] Fix meters example --- examples/Meters/Analogue_meters/Analogue_meters.ino | 11 ++++++++--- library.json | 2 +- library.properties | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/examples/Meters/Analogue_meters/Analogue_meters.ino b/examples/Meters/Analogue_meters/Analogue_meters.ino index dcc3c3c..c944a92 100644 --- a/examples/Meters/Analogue_meters/Analogue_meters.ino +++ b/examples/Meters/Analogue_meters/Analogue_meters.ino @@ -65,18 +65,23 @@ void loop() float value = 50.0 + 50.0 * sin((d + 0) * 0.0174532925); float current; - mapValue(value, current, (float)0.0, (float)100.0, (float)0.0, (float)2.0); + current = mapValue(value, (float)0.0, (float)100.0, (float)0.0, (float)2.0); //Serial.print("I = "); Serial.print(current); amps.updateNeedle(current, 0); float voltage; - mapValue(value, voltage, (float)0.0, (float)100.0, (float)0.0, (float)10.0); + voltage = mapValue(value, (float)0.0, (float)100.0, (float)0.0, (float)10.0); //Serial.print(", V = "); Serial.println(voltage); volts.updateNeedle(voltage, 0); float resistance; - mapValue(value, resistance, (float)0.0, (float)100.0, (float)0.0, (float)100.0); + resistance = mapValue(value, (float)0.0, (float)100.0, (float)0.0, (float)100.0); //Serial.print(", R = "); Serial.println(resistance); ohms.updateNeedle(resistance, 0); } } + +float mapValue(float ip, float ipmin, float ipmax, float tomin, float tomax) +{ + return tomin + (((tomax - tomin) * (ip - ipmin))/ (ipmax - ipmin)); +} diff --git a/library.json b/library.json index 62d340e..18a9fde 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eWidget", - "version": "0.0.3", + "version": "0.0.4", "keywords": "Arduino, tft, display, button, gui, graph, meter, slider", "description": "A TFT GUI widget library", "repository": diff --git a/library.properties b/library.properties index 313e12f..28a7ef8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eWidget -version=0.0.3 +version=0.0.4 author=Bodmer maintainer=Bodmer sentence=A TFT GUI widget library