Code: [Local Link Removed for Guests]
'******************************************************************************
'* *
'* A simple gauge the hard way ! *
'* *
'******************************************************************************
Gosub InitLCD
'tft.loadfont "/fonts/FreeMono9pt7b.bin", 10
tft.loadfont "/fonts/FreeSans12pt7b.bin", 11
'tft.loadfont "/fonts/FreeSans18pt7b.bin", 12
'tft.loadfont "/fonts/FreeSans24pt7b.bin", 13
vga.circle 400,240,200,black,1
gosub draw
do
gosub rotate
loop
wait
'###################################################################################
Draw:
For N = 0 to 359 step 30 'Draw the large ticks
A=2*Pi*n/360
B=A+(Pi*n/360)
C=A-(Pi*n/360)
X1=cos(a) * 220+400
Y1=sin(a) * 220+240
H$=str$(n)
vga.text.align 4
vga.text.color green
vga.text.draw H$, X1,Y1 ,11
Next N
vga.show
Return
'###################################################################################
Rotate:
angle=0
gosub Arrow
For Angle = -0.001 to 360 step 0.5
VGA.LINE x4, y4, CLx, CLy, black,11
VGA.LINE x5, y5, CLx, CLy, black,11
VGA.CIRCLE x6, y6, 35, black ,1
VGA.TRIANGLE x1, y1, x2, y2, x3, y3, black ,1
gosub Arrow
pause 120
next angle
Return
'###################################################################################
Arrow:
Inner=140
Outer=200
CLx=400
CLy=240
D=9 'Angular width of triangle
TW=D*2*Pi*1/360
Rad=Angle*2*Pi*1/360
A=Rad
B=Rad+TW
C=Rad-TW
X1=cos(a) * Outer+CLx
Y1=sin(a) * Outer+CLy
X2=cos(b) * Inner+CLx
Y2=sin(b) * Inner+CLy
X3=cos(c) * Inner+CLx
Y3=sin(c) * Inner+CLy
X4=cos(a) * (Outer-20)+CLx
Y4=sin(a) * (Outer-20)+CLy
X5=cos(a) * (-Outer+80)+CLx
Y5=sin(a) * (-Outer+80)+CLy
X6=cos(a) * (-Outer+80)+CLx
Y6=sin(a) * (-Outer+80)+CLy
X7=cos(a) * (-Outer+50)+CLx
Y7=sin(a) * (-Outer+50)+CLy
VGA.LINE x4, y4, CLx, CLy, white,11
VGA.LINE x5, y5, CLx, CLy, white,11
VGA.CIRCLE x6, y6, 35, white ,1
VGA.CIRCLE x7, y7, 40, black ,1
VGA.TRIANGLE x1, y1, x2, y2, x3, y3, white ,1
VGA.CIRCLE CLx, Cly, 11, white ,0
VGA.CIRCLE CLx, Cly, 9, black ,1
vga.show
Return
'###################################################################################
InitLCD:
'Note: Config options module must be set to custom - No TFT
'SPI Pins: MOSI=11, MISO=13, SCLK=12
'TFT pins all set to -1 SDcard CS=10
'I2S pins BCLK=0, WSEL=18, DOUT=17
vga.pinout 14, 21, 47, 48, 45, 9, 46, 3, 8, 16, 1, 15, 7, 6, 5, 4, 39, 40, 41, 42
vga.delete 'Reclaim memory
option.touch 1 'setup capacitive touch
i2c.setup 19, 20
touch.init 'initialise the capacitive touch
vga.init 12, 2
'pin.mode 2, output ' backlight
'pin(2) = 1 'is on pin 2
pwm.setup 2, 7, 128 'set backlight brightness 0-255
vgagui.init 50, tft.rgb(32,32,64)
Return