A simple meter using Adafruit 2.8 TFT with touch v2

Dependencies:   SPI_STMPE610 UniGraphic mbed vt100

/media/uploads/Rhyme/tester_s.jpg

A dumb simple voltage tester using ADC.
With FRDM-KL25Z, you can measure about 0V to 3.28V.
Nothing to drop your jaw nor holding your breath
but I wanted one, so I wrote one ;-)

とても単純はADCを使用した電圧テスターです。
FRDM-KL25Z を使用した場合、0V ~ 3.28V くらいが測定範囲です。
特に目新しいことも、驚くこともありませんが、
自分が欲しいので書いてみました (^ - ^)

On 18-May-2018 
I changed the number display from 0.00 to 0.000
so that I can measure the change of a small loadcell.

2018年5月18日 
ロードセル (重量センサ)の出力値の変化を見たかったので
有効数字を小数点以下2桁から3桁に変更しました。

Revision:
1:d7f2aa328962
Parent:
0:d01def9cf41e
Child:
2:204e60dbd73d
--- a/meter.cpp	Thu Jul 20 02:37:13 2017 +0000
+++ b/meter.cpp	Thu Jul 20 04:59:51 2017 +0000
@@ -26,15 +26,11 @@
 {
     double theta ;
     int i ;
-    for (i = 1 ; i < 450 ; i++ ) {
+    for (i = 0 ; i <= 450 ; i++ ) {
         theta = M_PI * (((double)(i + 450))/1800.0) ;
         SIN[i] = sin( theta ) ;
         COS[i] = cos( theta ) ;
     }
-    SIN[0] = 0.0 ;
-    COS[0] = 1.0 ;
-    SIN[450] = 1.0 ;
-    COS[450] = 0.0 ;
 }
 
 meter::meter(int x, int y, int width, int height, float min, float max) 
@@ -98,6 +94,8 @@
     int i ;
     
     theta = 90.0 - (90.0 * (value / _max)) ;
+    if (theta < 0.0) { theta = 0.0 ; }
+    if (theta > 90.0) { theta = 90.0 ; }
     if (theta > 45.0) {
         i = (10.0 * (90.0 - theta + 45.0) + 0.5) ; 
         x1 = _center_x -(radius * COS[i-450] + 0.5) ;
@@ -107,9 +105,11 @@
         x1 = _center_x + (radius * COS[i-450] + 0.5) ;
         x2 = _center_x + ((radius + append) * COS[i-450] + 0.5) ;
     }
+
     y1 = _center_y - (radius * SIN[i-450] + 0.5) ;
     y2 = _center_y - ((radius + append) * SIN[i-450] + 0.5) ;
     tft->BusEnable(true) ;
+    printf("i = %d (%d, %d) - (%d, %d)\n", i, x1, y1, x2, y2) ;
     tft->line(prev_x1, prev_y1, prev_x2, prev_y2, White) ;
     tft->line(x1, y1, x2, y2, Black) ;
     tft->BusEnable(false) ;