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桁に変更しました。

Committer:
Rhyme
Date:
Thu Jul 20 02:37:13 2017 +0000
Revision:
0:d01def9cf41e
Child:
3:bf8761c8eb17
first working version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:d01def9cf41e 1 #include "mbed.h"
Rhyme 0:d01def9cf41e 2 #include "ILI9341.h"
Rhyme 0:d01def9cf41e 3 #include "Arial12x12.h"
Rhyme 0:d01def9cf41e 4 #include "Arial24x23.h"
Rhyme 0:d01def9cf41e 5 #include "Arial28x28.h"
Rhyme 0:d01def9cf41e 6 #include "Arial43x48_numb.h"
Rhyme 0:d01def9cf41e 7 #include "SPI_STMPE610.h"
Rhyme 0:d01def9cf41e 8 #include "vt100.h"
Rhyme 0:d01def9cf41e 9 #include "meter.h"
Rhyme 0:d01def9cf41e 10 #include "main.h"
Rhyme 0:d01def9cf41e 11
Rhyme 0:d01def9cf41e 12 vt100 *tty = 0 ;
Rhyme 0:d01def9cf41e 13 ILI9341 *tft = 0 ;
Rhyme 0:d01def9cf41e 14 SPI_STMPE610 *tsc = 0 ;
Rhyme 0:d01def9cf41e 15 meter *tacho = 0 ;
Rhyme 0:d01def9cf41e 16
Rhyme 0:d01def9cf41e 17 DigitalOut myled(LED1, 1);
Rhyme 0:d01def9cf41e 18 DigitalOut *backlight = 0 ;
Rhyme 0:d01def9cf41e 19 AnalogIn *vin = 0 ;
Rhyme 0:d01def9cf41e 20
Rhyme 0:d01def9cf41e 21 float min_value = 0.0 ;
Rhyme 0:d01def9cf41e 22 float max_value = 3.3 ;
Rhyme 0:d01def9cf41e 23
Rhyme 0:d01def9cf41e 24 void initTFT(void)
Rhyme 0:d01def9cf41e 25 {
Rhyme 0:d01def9cf41e 26 //Configure the display driver
Rhyme 0:d01def9cf41e 27 tft->BusEnable(true) ;
Rhyme 0:d01def9cf41e 28 tft->FastWindow(true) ;
Rhyme 0:d01def9cf41e 29 tft->background(Black);
Rhyme 0:d01def9cf41e 30 tft->foreground(White);
Rhyme 0:d01def9cf41e 31 wait(0.01) ;
Rhyme 0:d01def9cf41e 32 tft->cls();
Rhyme 0:d01def9cf41e 33 tft->BusEnable(false) ;
Rhyme 0:d01def9cf41e 34 backlight = new DigitalOut(PIN_BL_TFT, 1) ;
Rhyme 0:d01def9cf41e 35 }
Rhyme 0:d01def9cf41e 36
Rhyme 0:d01def9cf41e 37 void init_hardware(void)
Rhyme 0:d01def9cf41e 38 {
Rhyme 0:d01def9cf41e 39 tty = new vt100() ;
Rhyme 0:d01def9cf41e 40 tty->cls() ;
Rhyme 0:d01def9cf41e 41 tft = new ILI9341(SPI_8, 10000000,
Rhyme 0:d01def9cf41e 42 PIN_MOSI, PIN_MISO, PIN_SCLK,
Rhyme 0:d01def9cf41e 43 PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ;
Rhyme 0:d01def9cf41e 44 initTFT() ;
Rhyme 0:d01def9cf41e 45 tft->set_font((unsigned char*) Arial28x28);
Rhyme 0:d01def9cf41e 46 tft->foreground(White) ;
Rhyme 0:d01def9cf41e 47 // tsc = new SPI_STMPE610(PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TSC) ;
Rhyme 0:d01def9cf41e 48 tacho = new meter(5, 5, 230, 230, 0.0, 3.3) ;
Rhyme 0:d01def9cf41e 49 vin = new AnalogIn(PIN_ADC_CH0) ;
Rhyme 0:d01def9cf41e 50 }
Rhyme 0:d01def9cf41e 51
Rhyme 0:d01def9cf41e 52 int main() {
Rhyme 0:d01def9cf41e 53 float value = 0.0 ;
Rhyme 0:d01def9cf41e 54 float prev_value = 0.0 ;
Rhyme 0:d01def9cf41e 55 int intvalue = 0 ;
Rhyme 0:d01def9cf41e 56 init_hardware() ;
Rhyme 0:d01def9cf41e 57 *backlight = 1 ;
Rhyme 0:d01def9cf41e 58
Rhyme 0:d01def9cf41e 59 tacho->drawFrame() ;
Rhyme 0:d01def9cf41e 60 tacho->drawScale() ;
Rhyme 0:d01def9cf41e 61 while(1) {
Rhyme 0:d01def9cf41e 62 value = 3.28 * vin->read() ;
Rhyme 0:d01def9cf41e 63 intvalue = (int)(100.0 * value + 0.5) ;
Rhyme 0:d01def9cf41e 64 value = (double)intvalue / 100.0 ;
Rhyme 0:d01def9cf41e 65 if (value != prev_value) {
Rhyme 0:d01def9cf41e 66 tacho->drawHand(value) ;
Rhyme 0:d01def9cf41e 67 tacho->drawValue(value) ;
Rhyme 0:d01def9cf41e 68 prev_value = value ;
Rhyme 0:d01def9cf41e 69 }
Rhyme 0:d01def9cf41e 70 wait(0.2) ;
Rhyme 0:d01def9cf41e 71 }
Rhyme 0:d01def9cf41e 72 }