A simple meter using Adafruit 2.8 TFT with touch v2
Dependencies: SPI_STMPE610 UniGraphic mbed vt100
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桁に変更しました。
main.cpp@4:0607a2a46238, 2018-05-18 (annotated)
- Committer:
- Rhyme
- Date:
- Fri May 18 01:25:32 2018 +0000
- Revision:
- 4:0607a2a46238
- Parent:
- 3:bf8761c8eb17
Changed the display value from 0.00 to 0.000
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 3:bf8761c8eb17 | 1 | /** |
Rhyme | 3:bf8761c8eb17 | 2 | * main.cpp |
Rhyme | 3:bf8761c8eb17 | 3 | */ |
Rhyme | 0:d01def9cf41e | 4 | #include "mbed.h" |
Rhyme | 0:d01def9cf41e | 5 | #include "ILI9341.h" |
Rhyme | 0:d01def9cf41e | 6 | #include "Arial28x28.h" |
Rhyme | 0:d01def9cf41e | 7 | #include "vt100.h" |
Rhyme | 0:d01def9cf41e | 8 | #include "meter.h" |
Rhyme | 0:d01def9cf41e | 9 | #include "main.h" |
Rhyme | 0:d01def9cf41e | 10 | |
Rhyme | 3:bf8761c8eb17 | 11 | #define ADC_MAX_VALUE 3.28 |
Rhyme | 3:bf8761c8eb17 | 12 | |
Rhyme | 0:d01def9cf41e | 13 | vt100 *tty = 0 ; |
Rhyme | 0:d01def9cf41e | 14 | ILI9341 *tft = 0 ; |
Rhyme | 0:d01def9cf41e | 15 | meter *tacho = 0 ; |
Rhyme | 0:d01def9cf41e | 16 | |
Rhyme | 0:d01def9cf41e | 17 | DigitalOut *backlight = 0 ; |
Rhyme | 0:d01def9cf41e | 18 | AnalogIn *vin = 0 ; |
Rhyme | 0:d01def9cf41e | 19 | |
Rhyme | 0:d01def9cf41e | 20 | float min_value = 0.0 ; |
Rhyme | 0:d01def9cf41e | 21 | float max_value = 3.3 ; |
Rhyme | 0:d01def9cf41e | 22 | |
Rhyme | 0:d01def9cf41e | 23 | void initTFT(void) |
Rhyme | 0:d01def9cf41e | 24 | { |
Rhyme | 0:d01def9cf41e | 25 | //Configure the display driver |
Rhyme | 0:d01def9cf41e | 26 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 27 | tft->FastWindow(true) ; |
Rhyme | 0:d01def9cf41e | 28 | tft->background(Black); |
Rhyme | 0:d01def9cf41e | 29 | tft->foreground(White); |
Rhyme | 0:d01def9cf41e | 30 | wait(0.01) ; |
Rhyme | 0:d01def9cf41e | 31 | tft->cls(); |
Rhyme | 0:d01def9cf41e | 32 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 33 | backlight = new DigitalOut(PIN_BL_TFT, 1) ; |
Rhyme | 0:d01def9cf41e | 34 | } |
Rhyme | 0:d01def9cf41e | 35 | |
Rhyme | 0:d01def9cf41e | 36 | void init_hardware(void) |
Rhyme | 0:d01def9cf41e | 37 | { |
Rhyme | 0:d01def9cf41e | 38 | tty = new vt100() ; |
Rhyme | 0:d01def9cf41e | 39 | tty->cls() ; |
Rhyme | 0:d01def9cf41e | 40 | tft = new ILI9341(SPI_8, 10000000, |
Rhyme | 3:bf8761c8eb17 | 41 | PIN_MOSI, PIN_MISO, PIN_SCLK, |
Rhyme | 3:bf8761c8eb17 | 42 | PIN_CS_TFT, PIN_RESET_TFT, PIN_DC_TFT, "Adafruit2.8") ; |
Rhyme | 0:d01def9cf41e | 43 | initTFT() ; |
Rhyme | 0:d01def9cf41e | 44 | tft->set_font((unsigned char*) Arial28x28); |
Rhyme | 0:d01def9cf41e | 45 | tft->foreground(White) ; |
Rhyme | 0:d01def9cf41e | 46 | tacho = new meter(5, 5, 230, 230, 0.0, 3.3) ; |
Rhyme | 0:d01def9cf41e | 47 | vin = new AnalogIn(PIN_ADC_CH0) ; |
Rhyme | 3:bf8761c8eb17 | 48 | *backlight = 1 ; |
Rhyme | 3:bf8761c8eb17 | 49 | } |
Rhyme | 3:bf8761c8eb17 | 50 | |
Rhyme | 3:bf8761c8eb17 | 51 | double getRoundedValue(void) |
Rhyme | 3:bf8761c8eb17 | 52 | { |
Rhyme | 3:bf8761c8eb17 | 53 | double value = 0.0 ; |
Rhyme | 3:bf8761c8eb17 | 54 | int intvalue = 0 ; |
Rhyme | 3:bf8761c8eb17 | 55 | value = ADC_MAX_VALUE * vin->read() ; |
Rhyme | 4:0607a2a46238 | 56 | intvalue = (int)(1000.0 * value + 0.5) ; |
Rhyme | 4:0607a2a46238 | 57 | value = (double)intvalue / 1000.0 ; |
Rhyme | 3:bf8761c8eb17 | 58 | return( value ) ; |
Rhyme | 0:d01def9cf41e | 59 | } |
Rhyme | 0:d01def9cf41e | 60 | |
Rhyme | 0:d01def9cf41e | 61 | int main() { |
Rhyme | 0:d01def9cf41e | 62 | float value = 0.0 ; |
Rhyme | 0:d01def9cf41e | 63 | float prev_value = 0.0 ; |
Rhyme | 3:bf8761c8eb17 | 64 | |
Rhyme | 0:d01def9cf41e | 65 | init_hardware() ; |
Rhyme | 3:bf8761c8eb17 | 66 | tacho->draw(value) ; |
Rhyme | 3:bf8761c8eb17 | 67 | |
Rhyme | 0:d01def9cf41e | 68 | while(1) { |
Rhyme | 3:bf8761c8eb17 | 69 | value = getRoundedValue() ; |
Rhyme | 4:0607a2a46238 | 70 | printf("%.2f\n", value) ; |
Rhyme | 0:d01def9cf41e | 71 | if (value != prev_value) { |
Rhyme | 3:bf8761c8eb17 | 72 | tacho->update(value) ; |
Rhyme | 0:d01def9cf41e | 73 | prev_value = value ; |
Rhyme | 0:d01def9cf41e | 74 | } |
Rhyme | 3:bf8761c8eb17 | 75 | wait(0.1) ; |
Rhyme | 0:d01def9cf41e | 76 | } |
Rhyme | 0:d01def9cf41e | 77 | } |