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桁に変更しました。
meter.cpp@2:204e60dbd73d, 2017-07-21 (annotated)
- Committer:
- Rhyme
- Date:
- Fri Jul 21 01:24:53 2017 +0000
- Revision:
- 2:204e60dbd73d
- Parent:
- 1:d7f2aa328962
- Child:
- 3:bf8761c8eb17
organizing index count for theta (on going)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:d01def9cf41e | 1 | #include "mbed.h" |
Rhyme | 0:d01def9cf41e | 2 | #include <math.h> |
Rhyme | 0:d01def9cf41e | 3 | #include <string.h> |
Rhyme | 0:d01def9cf41e | 4 | #include "ILI9341.h" |
Rhyme | 0:d01def9cf41e | 5 | #include "Arial12x12.h" |
Rhyme | 0:d01def9cf41e | 6 | #include "Arial24x23.h" |
Rhyme | 0:d01def9cf41e | 7 | #include "Arial28x28.h" |
Rhyme | 0:d01def9cf41e | 8 | #include "Arial43x48_numb.h" |
Rhyme | 0:d01def9cf41e | 9 | #include "SPI_STMPE610.h" |
Rhyme | 0:d01def9cf41e | 10 | #include "meter.h" |
Rhyme | 0:d01def9cf41e | 11 | #include "vt100.h" |
Rhyme | 0:d01def9cf41e | 12 | #include "main.h" |
Rhyme | 0:d01def9cf41e | 13 | |
Rhyme | 0:d01def9cf41e | 14 | #ifndef M_PI |
Rhyme | 0:d01def9cf41e | 15 | #define M_PI 3.141593 |
Rhyme | 0:d01def9cf41e | 16 | #endif |
Rhyme | 0:d01def9cf41e | 17 | |
Rhyme | 0:d01def9cf41e | 18 | extern vt100 *tty ; |
Rhyme | 0:d01def9cf41e | 19 | extern ILI9341 *tft ; |
Rhyme | 0:d01def9cf41e | 20 | extern SPI_STMPE610 *tsc ; |
Rhyme | 0:d01def9cf41e | 21 | extern meter *tacho ; |
Rhyme | 0:d01def9cf41e | 22 | double SIN[451] ; |
Rhyme | 0:d01def9cf41e | 23 | double COS[451] ; |
Rhyme | 0:d01def9cf41e | 24 | |
Rhyme | 0:d01def9cf41e | 25 | static void fillTriTable(void) |
Rhyme | 0:d01def9cf41e | 26 | { |
Rhyme | 0:d01def9cf41e | 27 | double theta ; |
Rhyme | 0:d01def9cf41e | 28 | int i ; |
Rhyme | 1:d7f2aa328962 | 29 | for (i = 0 ; i <= 450 ; i++ ) { |
Rhyme | 0:d01def9cf41e | 30 | theta = M_PI * (((double)(i + 450))/1800.0) ; |
Rhyme | 0:d01def9cf41e | 31 | SIN[i] = sin( theta ) ; |
Rhyme | 0:d01def9cf41e | 32 | COS[i] = cos( theta ) ; |
Rhyme | 0:d01def9cf41e | 33 | } |
Rhyme | 0:d01def9cf41e | 34 | } |
Rhyme | 0:d01def9cf41e | 35 | |
Rhyme | 0:d01def9cf41e | 36 | meter::meter(int x, int y, int width, int height, float min, float max) |
Rhyme | 0:d01def9cf41e | 37 | { |
Rhyme | 0:d01def9cf41e | 38 | _x = x ; |
Rhyme | 0:d01def9cf41e | 39 | _y = y ; |
Rhyme | 0:d01def9cf41e | 40 | _w = width ; |
Rhyme | 0:d01def9cf41e | 41 | _h = height ; |
Rhyme | 0:d01def9cf41e | 42 | _value = min ; |
Rhyme | 0:d01def9cf41e | 43 | _min = min ; |
Rhyme | 0:d01def9cf41e | 44 | _max = max ; |
Rhyme | 0:d01def9cf41e | 45 | _center_x = _x + _w / 2 ; |
Rhyme | 0:d01def9cf41e | 46 | _center_y = _y + (2 * _h) / 3 ; |
Rhyme | 0:d01def9cf41e | 47 | fillTriTable() ; |
Rhyme | 0:d01def9cf41e | 48 | } |
Rhyme | 0:d01def9cf41e | 49 | |
Rhyme | 0:d01def9cf41e | 50 | meter::~meter(void) |
Rhyme | 0:d01def9cf41e | 51 | { |
Rhyme | 0:d01def9cf41e | 52 | } |
Rhyme | 0:d01def9cf41e | 53 | |
Rhyme | 0:d01def9cf41e | 54 | void meter::drawFrame(void) |
Rhyme | 0:d01def9cf41e | 55 | { |
Rhyme | 0:d01def9cf41e | 56 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 57 | tft->fillrect(_x, _y, _x+ _w - 1, _y+(2 * _h)/3 - 1, White) ; |
Rhyme | 0:d01def9cf41e | 58 | tft->fillrect(_x, _y+(2 * _h)/3 - 1, _x + _w - 1, _y + _h - 1, Black) ; |
Rhyme | 0:d01def9cf41e | 59 | tft->rect(_x, _y, _x + _w - 1, _y + _h - 1, Green) ; |
Rhyme | 0:d01def9cf41e | 60 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 61 | } |
Rhyme | 0:d01def9cf41e | 62 | |
Rhyme | 0:d01def9cf41e | 63 | void meter::drawScale(void) |
Rhyme | 0:d01def9cf41e | 64 | { |
Rhyme | 0:d01def9cf41e | 65 | int x1, x2, y1, y2 ; |
Rhyme | 0:d01def9cf41e | 66 | double radius ; |
Rhyme | 0:d01def9cf41e | 67 | double append ; |
Rhyme | 0:d01def9cf41e | 68 | radius = _w / 2.0 ; |
Rhyme | 0:d01def9cf41e | 69 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 70 | for (int i = 0 ; i < 450 ; i += 45 ) { |
Rhyme | 0:d01def9cf41e | 71 | x1 = (radius * COS[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 72 | y1 = (radius * SIN[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 73 | if ((i % 10) == 5) { |
Rhyme | 0:d01def9cf41e | 74 | append = 5 ; |
Rhyme | 0:d01def9cf41e | 75 | } else { |
Rhyme | 0:d01def9cf41e | 76 | append = 10 ; |
Rhyme | 0:d01def9cf41e | 77 | } |
Rhyme | 0:d01def9cf41e | 78 | x2 = ((radius + append) * COS[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 79 | y2 = ((radius + append) * SIN[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 80 | tft->line(_center_x + x1, _center_y - y1, _center_x + x2, _center_y - y2, Black) ; |
Rhyme | 0:d01def9cf41e | 81 | tft->line(_center_x - x1, _center_y - y1, _center_x - x2, _center_y - y2, Black) ; |
Rhyme | 0:d01def9cf41e | 82 | } |
Rhyme | 0:d01def9cf41e | 83 | tft->line(_center_x, _center_y - radius, _center_x, _center_y - (radius + 10), Black) ; |
Rhyme | 0:d01def9cf41e | 84 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 85 | } |
Rhyme | 0:d01def9cf41e | 86 | |
Rhyme | 0:d01def9cf41e | 87 | void meter::drawHand(float value) |
Rhyme | 0:d01def9cf41e | 88 | { |
Rhyme | 0:d01def9cf41e | 89 | static int prev_x1 = 0, prev_x2 = 0, prev_y1 = 0, prev_y2 = 0 ; |
Rhyme | 0:d01def9cf41e | 90 | int x1, x2, y1, y2 ; |
Rhyme | 0:d01def9cf41e | 91 | double theta ; |
Rhyme | 0:d01def9cf41e | 92 | double radius = _w / 20.0 ; |
Rhyme | 0:d01def9cf41e | 93 | double append = 8.0 * (_w / 20.0) ; |
Rhyme | 0:d01def9cf41e | 94 | int i ; |
Rhyme | 0:d01def9cf41e | 95 | |
Rhyme | 0:d01def9cf41e | 96 | theta = 90.0 - (90.0 * (value / _max)) ; |
Rhyme | 1:d7f2aa328962 | 97 | if (theta < 0.0) { theta = 0.0 ; } |
Rhyme | 1:d7f2aa328962 | 98 | if (theta > 90.0) { theta = 90.0 ; } |
Rhyme | 0:d01def9cf41e | 99 | if (theta > 45.0) { |
Rhyme | 2:204e60dbd73d | 100 | i = (10.0 * (90.0 - theta + 45.0) + 0.5) - 450 ; |
Rhyme | 2:204e60dbd73d | 101 | x1 = _center_x -(radius * COS[i] + 0.5) ; |
Rhyme | 2:204e60dbd73d | 102 | x2 = _center_x -((radius + append) * COS[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 103 | } else { |
Rhyme | 2:204e60dbd73d | 104 | i = (10.0 * (theta + 45.0) + 0.5) - 450 ; |
Rhyme | 2:204e60dbd73d | 105 | x1 = _center_x + (radius * COS[i] + 0.5) ; |
Rhyme | 2:204e60dbd73d | 106 | x2 = _center_x + ((radius + append) * COS[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 107 | } |
Rhyme | 1:d7f2aa328962 | 108 | |
Rhyme | 2:204e60dbd73d | 109 | y1 = _center_y - (radius * SIN[i] + 0.5) ; |
Rhyme | 2:204e60dbd73d | 110 | y2 = _center_y - ((radius + append) * SIN[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 111 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 112 | tft->line(prev_x1, prev_y1, prev_x2, prev_y2, White) ; |
Rhyme | 0:d01def9cf41e | 113 | tft->line(x1, y1, x2, y2, Black) ; |
Rhyme | 0:d01def9cf41e | 114 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 115 | prev_x1 = x1 ; |
Rhyme | 0:d01def9cf41e | 116 | prev_x2 = x2 ; |
Rhyme | 0:d01def9cf41e | 117 | prev_y1 = y1 ; |
Rhyme | 0:d01def9cf41e | 118 | prev_y2 = y2 ; |
Rhyme | 0:d01def9cf41e | 119 | } |
Rhyme | 0:d01def9cf41e | 120 | |
Rhyme | 0:d01def9cf41e | 121 | void meter::draw(void) |
Rhyme | 0:d01def9cf41e | 122 | { |
Rhyme | 0:d01def9cf41e | 123 | } |
Rhyme | 0:d01def9cf41e | 124 | |
Rhyme | 0:d01def9cf41e | 125 | void meter::draw(float value) |
Rhyme | 0:d01def9cf41e | 126 | { |
Rhyme | 0:d01def9cf41e | 127 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 128 | drawHand(_value) ; |
Rhyme | 0:d01def9cf41e | 129 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 130 | } |
Rhyme | 0:d01def9cf41e | 131 | |
Rhyme | 0:d01def9cf41e | 132 | void meter::drawValue(float value) |
Rhyme | 0:d01def9cf41e | 133 | { |
Rhyme | 0:d01def9cf41e | 134 | char str[32] ; |
Rhyme | 0:d01def9cf41e | 135 | int v1, v2 ; |
Rhyme | 0:d01def9cf41e | 136 | v1 = (int)value ; |
Rhyme | 0:d01def9cf41e | 137 | v2 = ((int)(100.0 * value) % 100) ; |
Rhyme | 0:d01def9cf41e | 138 | sprintf(str, "%d.%02d V", v1, v2) ; |
Rhyme | 0:d01def9cf41e | 139 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 140 | tft->locate(80, 190) ; |
Rhyme | 0:d01def9cf41e | 141 | tft->printf(str) ; |
Rhyme | 0:d01def9cf41e | 142 | wait(0.01) ; |
Rhyme | 0:d01def9cf41e | 143 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 144 | } |
Rhyme | 0:d01def9cf41e | 145 | |
Rhyme | 0:d01def9cf41e | 146 | void meter::update(float value) |
Rhyme | 0:d01def9cf41e | 147 | { |
Rhyme | 0:d01def9cf41e | 148 | } |