Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:09 11 May 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : code snippet for RP2350 with PSRAM

Author Message
dddns
Senior Member

Joined: 20/09/2024
Location: Germany
Posts: 259
Posted: 01:10am 30 Mar 2025
Copy link to clipboard 
Print this post

Hello :)

I setup my first VGA system and played. Outcome is a fully customizable and scalable analog clock. So nothing special but might be useful. Runs real nice and flicker free:



Option explicit
Option angle degrees

Dim integer background = RGB(white)
Dim integer xpos,ypos

Dim integer clk_hand_col(15) = (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)
Colour Map clk_hand_col(),clk_hand_col()

Dim integer clk_radius = 200

Dim integer clk_face_bc = clk_hand_col(9)
Dim integer clk_face_fc = clk_hand_col(1)
Dim integer clk_face_lw = 10
Dim integer clk_face_sec_length = 10
Dim integer clk_face_5min_length = 20
Dim integer clk_face_sec_col = clk_hand_col(15)
Dim integer clk_face_5min_col = clk_hand_col(14)
Dim integer clk_face_sec_lw = 3
Dim integer clk_face_5min_lw = 5

Dim integer clk_hand_cover_radius = 10
Dim integer clk_hand_cover_lw = 3
Dim integer clk_hand_cover_bc = clk_hand_col(0)
Dim integer clk_hand_cover_fc = clk_hand_col(15)

Dim integer clk_hand_width_sec = 5
Dim integer clk_hand_length_sec = clk_radius - clk_face_lw
Dim integer clk_hand_bc_sec = clk_hand_col(0)
Dim integer clk_hand_fc_sec = clk_hand_col(1)

Dim integer clk_hand_width_min = 10
Dim integer clk_hand_length_min = clk_hand_length_sec - 20
Dim integer clk_hand_bc_min = clk_hand_col(0)
Dim integer clk_hand_fc_min = clk_hand_col(13)

Dim integer clk_hand_width_hr = 15
Dim integer clk_hand_length_hr = clk_hand_length_min - 30
Dim integer clk_hand_bc_hr = clk_hand_col(0)
Dim integer clk_hand_fc_hr = clk_hand_col(3)

Dim integer clk_hand_xp(2), clk_hand_yp(2),clk_hand_x_base, clk_hand_y_base, clk_hand_width
Dim integer clk_hand_base_diff, clk_hand_length, clk_hand_bc, clk_hand_fc, hand_value
Dim integer t, dx, dy, dx1, dy1, hr, min, sec
Dim string clk_time$

CLS background
MODE 3
FRAMEBUFFER create

Do
'  If Inkey$ <> "" Then Save image "b:clock.bmp"
 If Timer > 1000 Then
   Timer = 0
   clk_time$ = Time$
   draw_time(MM.HRES / 2, MM.VRES / 2, clk_time$)
 EndIf
Loop


Sub draw_time(xpos, ypos,clk_time$)

 FRAMEBUFFER write f
 CLS RGB(white)
 draw_clk_face(xpos,ypos)

 'Draw hour
 hr = (Asc(Mid$(clk_time$, Len(clk_time$) - 7, 1)) - 48) * 10 + Asc(Mid$(clk_time$, Len(clk_time$) - 6, 1)) - 48
 min = (Asc(Mid$(clk_time$, Len(clk_time$) - 4, 1)) - 48) * 10 + Asc(Mid$(clk_time$, Len(clk_time$) - 3, 1)) - 48
 min = min / 60 * 5
 If hr > 11 Then
 hr = (hr - 12) * 5
 Else
 hr = hr * 5
 EndIf
 hand_value = (hr + min - 30) * -6
 clk_hand_base_diff =  clk_hand_cover_radius - Sqr(clk_hand_cover_radius ^2 - (clk_hand_width_hr / 2) ^2)
 clk_hand_width = clk_hand_width_hr
 clk_hand_length = clk_hand_length_hr
 clk_hand_bc = clk_hand_bc_hr
 clk_hand_fc = clk_hand_fc_hr
 draw_clk_hand(xpos,ypos)
 'Draw minute
 min = (Asc(Mid$(clk_time$, Len(clk_time$) - 4, 1)) - 48) * 10 + Asc(Mid$(clk_time$, Len(clk_time$) - 3, 1)) - 48
 hand_value = (min - 30) * -6
 clk_hand_base_diff =  clk_hand_cover_radius - Sqr(clk_hand_cover_radius ^2 - (clk_hand_width_min / 2) ^2)
 clk_hand_width = clk_hand_width_min
 clk_hand_length = clk_hand_length_min
 clk_hand_bc = clk_hand_bc_min
 clk_hand_fc = clk_hand_fc_min
 draw_clk_hand(xpos,ypos)
 'Draw second
 sec = (Asc(Mid$(clk_time$, Len(clk_time$) - 1, 1)) - 48) * 10 + Asc(Right$(clk_time$, 1)) - 48
 hand_value = (sec - 30) * -6
 clk_hand_base_diff =  clk_hand_cover_radius - Sqr(clk_hand_cover_radius ^2 - (clk_hand_width_sec / 2) ^2)
 clk_hand_width = clk_hand_width_sec
 clk_hand_length = clk_hand_length_sec
 clk_hand_bc = clk_hand_bc_sec
 clk_hand_fc = clk_hand_fc_sec
 draw_clk_hand(xpos,ypos)

 Circle xpos, ypos, clk_hand_cover_radius, clk_hand_cover_lw,, clk_hand_cover_bc, clk_hand_cover_fc
 FRAMEBUFFER copy f,n
End Sub


Sub draw_clk_hand(xpos,ypos)
 clk_hand_x_base = (clk_hand_cover_radius - clk_hand_base_diff) * Sin(hand_value)
 clk_hand_y_base = (clk_hand_cover_radius - clk_hand_base_diff) * Cos(hand_value)
 clk_hand_xp(0) = clk_hand_length * Sin(hand_value)
 clk_hand_yp(0) = clk_hand_length * Cos(hand_value)
 clk_hand_xp(1) = clk_hand_x_base - Cos(hand_value) * clk_hand_width / 2
 clk_hand_yp(1) = clk_hand_y_base + Sin(hand_value) * clk_hand_width / 2
 clk_hand_xp(2) = clk_hand_x_base + Cos(hand_value) * clk_hand_width / 2
 clk_hand_yp(2) = clk_hand_y_base - Sin(hand_value) * clk_hand_width / 2
 For t = 0 To 2
   clk_hand_xp(t) = clk_hand_xp(t) + xpos
   clk_hand_yp(t) = clk_hand_yp(t) + ypos
 Next t
 Polygon 3, clk_hand_xp(), clk_hand_yp(), clk_hand_bc, clk_hand_fc
End Sub

Sub draw_clk_face(xpos,ypos)
 Circle xpos, ypos, clk_radius, clk_face_lw,, clk_face_fc, clk_face_bc

 For sec = 0 To 360 Step 6
   dx = Sin(sec) * (clk_radius - clk_face_lw - clk_face_sec_length)
   dy = Cos(sec) * (clk_radius - clk_face_lw - clk_face_sec_length)
   dx1 = Sin(sec) * (clk_radius - clk_face_lw)
   dy1 = Cos(sec) * (clk_radius - clk_face_lw)
   Line dx + xpos, dy + ypos, dx1 + xpos, dy1 + ypos, clk_face_sec_lw, clk_face_sec_col
 Next sec
 For min = 0 To 360 Step 30
   dx = Sin(min) * (clk_radius - clk_face_lw - clk_face_5min_length)
   dy = Cos(min) * (clk_radius - clk_face_lw - clk_face_5min_length)
   dx1 = Sin(min) * (clk_radius - clk_face_lw)
   dy1 = Cos(min) * (clk_radius - clk_face_lw)
   Line dx + xpos, dy + ypos, dx1 + xpos, dy1 + ypos, clk_face_5min_lw, clk_face_5min_col
 Next min
End Sub
analog_clock.bas.zip
 
IanT
Senior Member

Joined: 29/11/2016
Location: United Kingdom
Posts: 105
Posted: 08:24am 30 Mar 2025
Copy link to clipboard 
Print this post

Thank You!  

Regards,


IanT
 
dddns
Senior Member

Joined: 20/09/2024
Location: Germany
Posts: 259
Posted: 12:28pm 30 Mar 2025
Copy link to clipboard 
Print this post

I realized, that this demo runs without PSRAM under RESOLUTION 640 and 720!

A simple "screensaver" made out of it:
analog_clock_screensaver.bas.zip
 
dddns
Senior Member

Joined: 20/09/2024
Location: Germany
Posts: 259
Posted: 11:48pm 30 Mar 2025
Copy link to clipboard 
Print this post

One more in this issue.
Two or more moving:

Tree or more connected through a polygon moving:

analog_clock_screensaverV2.bas.zip

Code could be optimized but this was just an exercise and I'm too lazy.
But if you like, do what you want with it :) have fun
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025