PicoMite demo on the Waveshare RP2040-LCD-1.28
| Author | Message | ||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11865 |
https://www.youtube.com/watch?v=flaFdoR4pJo The PicoMite supports the SSD1963 displays but these are now expensive and use nearly all the I/O pins. However, there are lots of SPI displays available. These have two downsides. First: they are comparatively slow as they rely on serial data transmission. Second: many of them don't support reading the controllers framebuffer and even those that do are even slower in read mode than in write mode. I therefore decided to add some extra functionality to get round this. The limitation is that the memory in the RP2040 isn't nearly big enough to hold a complete framebuffer for even a 240x240 display like the Waveshare RP2040-LCD-1.28 in its normal resolution (RGB565 = 2 bytes per pixel). So I have used some of the code from the PicoMiteVGA to create a memory framebuffer at RGB121 like the PicoMiteVGA. This allows me to create two memory framebuffers and still have plenty of space for variables. The demo uses this new functionality to create an artefact free moving display. I'll post the new firmware once a bit of tidying has been completed Option explicit Option default none ' Const Y_top = 0 'Y coordinate of top of the image file on the screen Const X_left = 0 'X coordinate of left of the image file on the screen Const s_Y_point = 172 'Y coordinate of the centre of the second hand relative to the image top Const s_X_point = 119 'X coordinate of the centre of the second hand relative to the image left Const h_Y_point = 119 'Y coordinate of the centre of the hour and minute hands relative to the image top Const h_X_point = 120 'X coordinate of the centre of the hour and minute hands relative to the image top Const sl=-30 Const ml=-100 Const hl=-75 ' ' ' ' Now we define the pointers as the X,Y coordinates of a number of triangles with the rotation point at 0,0 ' It is simplest to define this in the 12-oclock position which means the Y-coordinates at the top of the pointer will be negative ' The order of data elements in the array is: ' t1x1,t1y1,t1x2,t1y2,t1x3,t1y3, t2x1,t2y1,t2x2,t2y2,t2x3,t2y3,...tntx1,tnty1,tntx2,tnty2,tntx3,tnty3 ' Dim integer nt=6 'Number of triangles used to define the pointer Dim integer x1(nt-1)=(-1,-1,-2,-2,-3,-3) Dim integer y1(nt-1)=(0,0,0,0,0,0) Dim integer x2(nt-1)=(-1,1,-2,2,-3,3) Dim integer y2(nt-1)=(sl,sl,ml,ml,hl,hl) Dim integer x3(nt-1)=(1,1,2,2,3,3) Dim integer y3(nt-1)=(sl,0,ml,0,hl,0) Dim INTEGER pcolour=RGB(Green) 'define the colour of the pointer Const s_pivot=3, m_pivot=5, h_pivot=3 'diameter in pixels of the fulcrum of the pointer ' Dim integer xx0(nt-1),yy0(nt-1),xx1(nt-1),yy1(nt-1),xx2(nt-1),yy2(nt-1),tcol(nt-1) Dim integer first=1 'marker to control alternate processing on first time through the loop ' FRAMEBUFFER create FRAMEBUFFER layer FRAMEBUFFER write l CLS Load image "face" ' ' demo code moving the pointer Dim float secondangle=0, minuteangle=0, hourangle=0 Do FRAMEBUFFER copy l,f If secondangle Mod 60=0 Then Inc minuteangle,1 If (minuteangle Mod 72=0) And (secondangle Mod 60=0) Then Inc hourangle,6 drawpointer FRAMEBUFFER copy f,n Inc secondangle,6 Loop ' Sub drawpointer Local integer i,x,y Local float angle For i=0 To nt-1 If i<2 Then x=s_X_point y=s_Y_point pcolour=RGB(green) angle=secondangle Else x=h_X_point y=h_Y_point pcolour=RGB(white) If i<4 Then angle=minuteangle Else angle=hourangle EndIf EndIf rotatetriangle(i,pcolour,angle,x+X_left,y+Y_top,x1(i),y1(i),x2(i),y2(i),x3(i),y3(i)) 'rotate the pointer into the drawing array Next i FRAMEBUFFER write f Triangle xx0(), yy0(), xx1(), yy1(), xx2(), yy2(),tcol(),tcol() drawpivot End Sub Sub rotatetriangle(n As integer, col As integer, angle As float, x As integer, y As integer, x0 As integer, y0 As integer, x1 As in teger, y1 As integer, x2 As integer, y2 As integer) Local float sine=Sin(Rad(angle)),cosine=Cos(Rad(angle)) Local integer x0a,y0a,x1a,y1a,x2a,y2a x0a= x0*cosine - y0 * sine + x y0a= y0*cosine + x0 * sine + y x1a= x1*cosine - y1 * sine + x y1a= y1*cosine + x1 * sine + y x2a= x2*cosine - y2 * sine + x y2a= y2*cosine + x2 * sine + y xx0(n)=x0a yy0(n)=y0a xx1(n)=x1a yy1(n)=y1a xx2(n)=x2a yy2(n)=y2a tcol(n)=pcolour End Sub ' Sub drawpivot() 'put anything you like here to draw the fulcrum as you wish Circle s_X_point+X_left,s_Y_point+Y_top,s_pivot,0,,,RGB(green) Circle h_X_point+X_left,h_Y_point+Y_top,m_pivot,0,,,RGB(white) Circle h_X_point+X_left,h_Y_point+Y_top,h_pivot,0,,,RGB(black) End Sub Edited 2023-01-01 22:19 by matherp |
||||