analog power meter

Code tips and tricks for beginners
Post Reply
RonS
Posts: 115
Joined: Thu Mar 02, 2023 10:15 pm
Location: germany
Has thanked: 64 times
Been thanked: 23 times

analog power meter

Post by RonS »

As a component of my solar "monitoring project", I have "tinkered" here

for VGA Monitor 640 * 480

image.png

Code: [Local Link Removed for Guests]

'Annex32-S3 CAN DMT VGA 1.51.1 qio opi LFS
'VGA.PINOUT R0, R1, R2, G0, G1, G2, B0, B1, HSYNC, VSYNC
vga.pinout 12,13,14,18,8,3,5,6, 4,9
tft.loadfont "/fonts/FreeSansBold20pt7b.bin", 10
vga.delete
vga.init 2 ' VGA 640x480
'timer0 50, ticker
VGA.TEXT.COLOR white
vga.fill black
vga.text.size 2

do
FOR value = 90 to 270
pause 30
if value=270 then value=90
gosub L_meter
next value

loop
OPTION.WLOG 1

L_meter:'gauge
'VGA.RECT x, y, w, h, color [,fill]
vga.RECT 240, 220, 220, 145, white,0,45
vga.RECT 250, 225, 200, 200, white,1,45
'TFT.CIRCLE x, y, radius,color [, fill]
vga.circle 350,325,90,yellow,1
vga.circle 350,325,90,black
vga.RECT 250, 345, 200, 80,gold,1,5

vga.line 250,345,450,345,black,5
'VGA.TEXT.COLOR color [,background]
VGA.TEXT.COLOR black 
VGA.TEXT.SIZE 2
vga.text.draw "0", 260,360
vga.text.draw "400", 350,245
vga.text.draw "800", 430,360
VGA.TEXT.SIZE 5 
vga.text.draw "POWER", 350,390
val1=value/1
'VGA.NEEDLE x, y, length, angle, color [,thickness=1]
vga.needle 350,325,90,val1,red,10
vga.show

return

wait
here is the way to calculate your own values:
example your value is 400

Code: [Local Link Removed for Guests]

' Assumptions
Min_Scale = 90
Max_Scale = 270
Min_Input = 0
Max_Input = 800
Value = 400

' Step 1: Calculate the proportion of input in the range
Proportion = (Value - Min_Input) / (Max_Input - Min_Input)

' Step 2: Apply the proportion to the scale range
Result = Min_Scale + Proportion * (Max_Scale - Min_Scale)

' Output the result
Output "Result: "; Result





I am always grateful for tips and hints

Ron
You do not have the required permissions to view the files attached to this post.
Modules : 3xESP32-Cam MB (Chip"DM ESP32 S" ),AI-Thinker Audio Kit (ES8388), ESP32 Dev Kit with Display
RonS
Posts: 115
Joined: Thu Mar 02, 2023 10:15 pm
Location: germany
Has thanked: 64 times
Been thanked: 23 times

Re: analog power meter

Post by RonS »

latest version
image.png
You do not have the required permissions to view the files attached to this post.
Modules : 3xESP32-Cam MB (Chip"DM ESP32 S" ),AI-Thinker Audio Kit (ES8388), ESP32 Dev Kit with Display
User avatar
cicciocb
Site Admin
Posts: 1989
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 426 times
Been thanked: 1329 times
Contact:

Re: analog power meter

Post by cicciocb »

Hi Ron,
why you don't simply use a bmp image as as the instrument bezel ?
RonS
Posts: 115
Joined: Thu Mar 02, 2023 10:15 pm
Location: germany
Has thanked: 64 times
Been thanked: 23 times

Re: analog power meter

Post by RonS »

I also thought at the beginning to use a picture, but didn't find one that I liked - but the image has to be reloaded after every position change of the "needle" because the "needle" does not delete itself - or did I see something wrong there? or?
Modules : 3xESP32-Cam MB (Chip"DM ESP32 S" ),AI-Thinker Audio Kit (ES8388), ESP32 Dev Kit with Display
User avatar
cicciocb
Site Admin
Posts: 1989
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 426 times
Been thanked: 1329 times
Contact:

Re: analog power meter

Post by cicciocb »

Try this example and you'll understand how do it

(simply upload it using the file manager (zip files upload) and the load images4b.bas
You do not have the required permissions to view the files attached to this post.
Post Reply