Page 1 of 1

analog power meter

Posted: Sat Oct 07, 2023 2:07 pm
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

Re: analog power meter

Posted: Sat Oct 07, 2023 7:15 pm
by RonS
latest version
image.png

Re: analog power meter

Posted: Sun Oct 08, 2023 7:21 am
by cicciocb
Hi Ron,
why you don't simply use a bmp image as as the instrument bezel ?

Re: analog power meter

Posted: Sun Oct 08, 2023 8:34 am
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?

Re: analog power meter

Posted: Sun Oct 08, 2023 9:13 am
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