![](/media/cache/profiles/0d382a5fec7012c843c1bdfb0935c9a6.50x50_q85.jpg)
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@0:d01def9cf41e, 2017-07-20 (annotated)
- Committer:
- Rhyme
- Date:
- Thu Jul 20 02:37:13 2017 +0000
- Revision:
- 0:d01def9cf41e
- Child:
- 1:d7f2aa328962
first working version
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 | 0:d01def9cf41e | 29 | for (i = 1 ; 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 | SIN[0] = 0.0 ; |
Rhyme | 0:d01def9cf41e | 35 | COS[0] = 1.0 ; |
Rhyme | 0:d01def9cf41e | 36 | SIN[450] = 1.0 ; |
Rhyme | 0:d01def9cf41e | 37 | COS[450] = 0.0 ; |
Rhyme | 0:d01def9cf41e | 38 | } |
Rhyme | 0:d01def9cf41e | 39 | |
Rhyme | 0:d01def9cf41e | 40 | meter::meter(int x, int y, int width, int height, float min, float max) |
Rhyme | 0:d01def9cf41e | 41 | { |
Rhyme | 0:d01def9cf41e | 42 | _x = x ; |
Rhyme | 0:d01def9cf41e | 43 | _y = y ; |
Rhyme | 0:d01def9cf41e | 44 | _w = width ; |
Rhyme | 0:d01def9cf41e | 45 | _h = height ; |
Rhyme | 0:d01def9cf41e | 46 | _value = min ; |
Rhyme | 0:d01def9cf41e | 47 | _min = min ; |
Rhyme | 0:d01def9cf41e | 48 | _max = max ; |
Rhyme | 0:d01def9cf41e | 49 | _center_x = _x + _w / 2 ; |
Rhyme | 0:d01def9cf41e | 50 | _center_y = _y + (2 * _h) / 3 ; |
Rhyme | 0:d01def9cf41e | 51 | fillTriTable() ; |
Rhyme | 0:d01def9cf41e | 52 | } |
Rhyme | 0:d01def9cf41e | 53 | |
Rhyme | 0:d01def9cf41e | 54 | meter::~meter(void) |
Rhyme | 0:d01def9cf41e | 55 | { |
Rhyme | 0:d01def9cf41e | 56 | } |
Rhyme | 0:d01def9cf41e | 57 | |
Rhyme | 0:d01def9cf41e | 58 | void meter::drawFrame(void) |
Rhyme | 0:d01def9cf41e | 59 | { |
Rhyme | 0:d01def9cf41e | 60 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 61 | tft->fillrect(_x, _y, _x+ _w - 1, _y+(2 * _h)/3 - 1, White) ; |
Rhyme | 0:d01def9cf41e | 62 | tft->fillrect(_x, _y+(2 * _h)/3 - 1, _x + _w - 1, _y + _h - 1, Black) ; |
Rhyme | 0:d01def9cf41e | 63 | tft->rect(_x, _y, _x + _w - 1, _y + _h - 1, Green) ; |
Rhyme | 0:d01def9cf41e | 64 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 65 | } |
Rhyme | 0:d01def9cf41e | 66 | |
Rhyme | 0:d01def9cf41e | 67 | void meter::drawScale(void) |
Rhyme | 0:d01def9cf41e | 68 | { |
Rhyme | 0:d01def9cf41e | 69 | int x1, x2, y1, y2 ; |
Rhyme | 0:d01def9cf41e | 70 | double radius ; |
Rhyme | 0:d01def9cf41e | 71 | double append ; |
Rhyme | 0:d01def9cf41e | 72 | radius = _w / 2.0 ; |
Rhyme | 0:d01def9cf41e | 73 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 74 | for (int i = 0 ; i < 450 ; i += 45 ) { |
Rhyme | 0:d01def9cf41e | 75 | x1 = (radius * COS[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 76 | y1 = (radius * SIN[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 77 | if ((i % 10) == 5) { |
Rhyme | 0:d01def9cf41e | 78 | append = 5 ; |
Rhyme | 0:d01def9cf41e | 79 | } else { |
Rhyme | 0:d01def9cf41e | 80 | append = 10 ; |
Rhyme | 0:d01def9cf41e | 81 | } |
Rhyme | 0:d01def9cf41e | 82 | x2 = ((radius + append) * COS[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 83 | y2 = ((radius + append) * SIN[i] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 84 | tft->line(_center_x + x1, _center_y - y1, _center_x + x2, _center_y - y2, Black) ; |
Rhyme | 0:d01def9cf41e | 85 | tft->line(_center_x - x1, _center_y - y1, _center_x - x2, _center_y - y2, Black) ; |
Rhyme | 0:d01def9cf41e | 86 | } |
Rhyme | 0:d01def9cf41e | 87 | tft->line(_center_x, _center_y - radius, _center_x, _center_y - (radius + 10), Black) ; |
Rhyme | 0:d01def9cf41e | 88 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 89 | } |
Rhyme | 0:d01def9cf41e | 90 | |
Rhyme | 0:d01def9cf41e | 91 | void meter::drawHand(float value) |
Rhyme | 0:d01def9cf41e | 92 | { |
Rhyme | 0:d01def9cf41e | 93 | static int prev_x1 = 0, prev_x2 = 0, prev_y1 = 0, prev_y2 = 0 ; |
Rhyme | 0:d01def9cf41e | 94 | int x1, x2, y1, y2 ; |
Rhyme | 0:d01def9cf41e | 95 | double theta ; |
Rhyme | 0:d01def9cf41e | 96 | double radius = _w / 20.0 ; |
Rhyme | 0:d01def9cf41e | 97 | double append = 8.0 * (_w / 20.0) ; |
Rhyme | 0:d01def9cf41e | 98 | int i ; |
Rhyme | 0:d01def9cf41e | 99 | |
Rhyme | 0:d01def9cf41e | 100 | theta = 90.0 - (90.0 * (value / _max)) ; |
Rhyme | 0:d01def9cf41e | 101 | if (theta > 45.0) { |
Rhyme | 0:d01def9cf41e | 102 | i = (10.0 * (90.0 - theta + 45.0) + 0.5) ; |
Rhyme | 0:d01def9cf41e | 103 | x1 = _center_x -(radius * COS[i-450] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 104 | x2 = _center_x -((radius + append) * COS[i-450] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 105 | } else { |
Rhyme | 0:d01def9cf41e | 106 | i = (10.0 * (theta + 45.0) + 0.5) ; |
Rhyme | 0:d01def9cf41e | 107 | x1 = _center_x + (radius * COS[i-450] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 108 | x2 = _center_x + ((radius + append) * COS[i-450] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 109 | } |
Rhyme | 0:d01def9cf41e | 110 | y1 = _center_y - (radius * SIN[i-450] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 111 | y2 = _center_y - ((radius + append) * SIN[i-450] + 0.5) ; |
Rhyme | 0:d01def9cf41e | 112 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 113 | tft->line(prev_x1, prev_y1, prev_x2, prev_y2, White) ; |
Rhyme | 0:d01def9cf41e | 114 | tft->line(x1, y1, x2, y2, Black) ; |
Rhyme | 0:d01def9cf41e | 115 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 116 | prev_x1 = x1 ; |
Rhyme | 0:d01def9cf41e | 117 | prev_x2 = x2 ; |
Rhyme | 0:d01def9cf41e | 118 | prev_y1 = y1 ; |
Rhyme | 0:d01def9cf41e | 119 | prev_y2 = y2 ; |
Rhyme | 0:d01def9cf41e | 120 | } |
Rhyme | 0:d01def9cf41e | 121 | |
Rhyme | 0:d01def9cf41e | 122 | void meter::draw(void) |
Rhyme | 0:d01def9cf41e | 123 | { |
Rhyme | 0:d01def9cf41e | 124 | } |
Rhyme | 0:d01def9cf41e | 125 | |
Rhyme | 0:d01def9cf41e | 126 | void meter::draw(float value) |
Rhyme | 0:d01def9cf41e | 127 | { |
Rhyme | 0:d01def9cf41e | 128 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 129 | drawHand(_value) ; |
Rhyme | 0:d01def9cf41e | 130 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 131 | } |
Rhyme | 0:d01def9cf41e | 132 | |
Rhyme | 0:d01def9cf41e | 133 | void meter::drawValue(float value) |
Rhyme | 0:d01def9cf41e | 134 | { |
Rhyme | 0:d01def9cf41e | 135 | char str[32] ; |
Rhyme | 0:d01def9cf41e | 136 | int v1, v2 ; |
Rhyme | 0:d01def9cf41e | 137 | v1 = (int)value ; |
Rhyme | 0:d01def9cf41e | 138 | v2 = ((int)(100.0 * value) % 100) ; |
Rhyme | 0:d01def9cf41e | 139 | sprintf(str, "%d.%02d V", v1, v2) ; |
Rhyme | 0:d01def9cf41e | 140 | tft->BusEnable(true) ; |
Rhyme | 0:d01def9cf41e | 141 | tft->locate(80, 190) ; |
Rhyme | 0:d01def9cf41e | 142 | tft->printf(str) ; |
Rhyme | 0:d01def9cf41e | 143 | wait(0.01) ; |
Rhyme | 0:d01def9cf41e | 144 | tft->BusEnable(false) ; |
Rhyme | 0:d01def9cf41e | 145 | } |
Rhyme | 0:d01def9cf41e | 146 | |
Rhyme | 0:d01def9cf41e | 147 | void meter::update(float value) |
Rhyme | 0:d01def9cf41e | 148 | { |
Rhyme | 0:d01def9cf41e | 149 | } |