![]() |
Forum Index : Microcontroller and PC projects : TFT as a 7 segment display
Author | Message | ||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6268 |
This is a basic way of printing 7 segment style numbers using 'draw filled rectangle' from Peter's TFT code. It has 3 sizes. This image is size '2' Each digit takes between 18 and 44 mS to draw, depending on the number of segments. Replace the T18_test sub with: '
SUB T18_test LOCAL INTEGER i, xfs, yfs, x0, y0, x1, y1, wi, ht, sz LOCAL FLOAT tn T18.fillscreen(black) T18.setrot(T18_normal) T18.pbitmap(58, 2, &HFF81818181FF, 1, 0, green, black) T18.pstring(24, 12, "Welcome to the", 1, 0, green, black) T18.pstring(8, 30, "Micromite", 2, 0, red, black) T18.pstring(44,50,"MK2",2,0,red,black) T18.pstring(8, 80, "in colour", 2, 0, yellow, black) T18.pstring(10, 100, "1.8in SPI display", 1, 0, cyan, black) T18.pstring(7, 115, "S6D02A1 controller", 1, 0, cyan, black) T18.drect(0, 0, T18_params(T18_wi), T18_params(T18_ht), red) ' PAUSE 2000 T18.fillscreen(black) T18.pstring(12, 80, "Simple 7 segment", 1, 0, yellow, black) count end sub sub count local n as integer, colour as integer, w as integer for n = 0 to 99 if n>89 then colour = red else colour = green end if if n>9 then draw7segment( n\10, 20,100,colour,2) draw7segment( n mod 10, 60,100,colour,2) else draw7segment( n\10, 40,130,colour,1) draw7segment( n mod 10, 60,130,colour,1) end if pause 940 next n end sub SUB draw7segment(v as integer, x AS INTEGER, y AS INTEGER, rcolour AS INTEGER, w as integer) ' number, top left x, top left y, colour, size (1, 2 or 3) local i as integer T18.frect(x, y, 20*w, 30*w, black) select case v case 0 for i = 1 to 6 drawSegment(i, x , y , rcolour, w ) next i case 1 drawSegment(2, x , y , rcolour, w ) drawSegment(3, x , y , rcolour, w) case 2 drawSegment(1, x , y , rcolour, w ) drawSegment(2, x , y , rcolour, w ) drawSegment(4, x , y , rcolour, w ) drawSegment(5, x , y , rcolour, w ) drawSegment(7, x , y , rcolour, w ) case 3 for i = 1 to 4 drawSegment(i, x , y , rcolour, w ) next i drawSegment(7, x , y , rcolour, w ) case 4 drawSegment(2, x , y , rcolour, w ) drawSegment(3, x , y , rcolour, w ) drawSegment(6, x , y , rcolour, w ) drawSegment(7, x , y , rcolour, w ) case 5 drawSegment(1, x , y , rcolour, w ) drawSegment(3, x , y , rcolour, w ) drawSegment(4, x , y , rcolour, w ) drawSegment(6, x , y , rcolour, w ) drawSegment(7, x , y , rcolour, w ) case 6 drawSegment(1, x , y , rcolour, w ) for i = 3 to 7 drawSegment(i, x , y , rcolour, w ) next i case 7 for i = 1 to 3 drawSegment(i, x , y , rcolour, w ) next i case 8 for i = 1 to 8 drawSegment(i, x , y , rcolour, w ) next i case 9 for i = 1 to 4 drawSegment(i, x , y , rcolour, w ) next i drawSegment(6, x , y , rcolour, w ) drawSegment(7, x , y , rcolour, w ) end select end sub sub drawSegment(s as integer, x AS INTEGER, y AS INTEGER, rcolour AS INTEGER, w as integer) if w < 1 then w = 1 if w > 3 then w = 3 select case s case 1 T18.frndrect(x+4*w, y+3*w, 12*w, 2*w, w, rcolour) case 2 T18.frndrect(x+15*w, y+4*w, 2*w, 10*w, w, rcolour) case 3 T18.frndrect(x+15*w, y+14*w, 2*w, 10*w, w, rcolour) case 4 T18.frndrect(x+4*w, y+23*w, 12*w, 2*w, w, rcolour) case 5 T18.frndrect(x+3*w, y+14*w, 2*w, 10*w, w, rcolour) case 6 T18.frndrect(x+3*w, y+4*w, 2*w, 10*w, w, rcolour) case 7 T18.frndrect(x+4*w, y+13*w, 12*w, 2*w, w, rcolour) end select end sub Decimal points should be easy to add if required. Jim VK7JH MMedit |
||||
Zonker![]() Guru ![]() Joined: 18/08/2012 Location: United StatesPosts: 767 |
Sweet add-on Tassy..! Maybe decimal points, the degree symbol and a colon thingy would be good... I just got in the 1.8" displays and got one going last night... Maybe if I can get more time this week, I can get this working ok... Looks good on the Display..! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6268 |
Decimal points and the colon are simply filled circles. Degree is an unfilled circle. New numbers will likely over-write the DP so it would have to be re entered after each write. To keep you going, here is an update that has size zero numbers. SUB T18_test
LOCAL INTEGER i, xfs, yfs, x0, y0, x1, y1, wi, ht, sz LOCAL FLOAT tn T18.fillscreen(black) T18.setrot(T18_normal) T18.pbitmap(58, 2, &HFF81818181FF, 1, 0, green, black) T18.pstring(24, 12, "Welcome to the", 1, 0, green, black) T18.pstring(8, 30, "Micromite", 2, 0, red, black) T18.pstring(44,50,"MK2",2,0,red,black) T18.pstring(8, 80, "in colour", 2, 0, yellow, black) T18.pstring(10, 100, "1.8in SPI display", 1, 0, cyan, black) T18.pstring(7, 115, "S6D02A1 controller", 1, 0, cyan, black) T18.drect(0, 0, T18_params(T18_wi), T18_params(T18_ht), red) ' PAUSE 2000 T18.fillscreen(black) T18.pstring(12, 80, "Simple 7 segment", 1, 0, yellow, black) count end sub Jim sub count local n as integer, colour as integer, w as integer for n = 0 to 99 if n>89 then colour = red else colour = green end if if n>9 then draw7segment( n\10, 20,100,colour,2) draw7segment( n mod 10, 60,100,colour,2) else draw7segment( n\10, 40,130,colour,0) draw7segment( n mod 10, 60,130,colour,0) end if pause 940 next n end sub SUB draw7segment(v as integer, x AS INTEGER, y AS INTEGER, rcolour AS INTEGER, w as integer) ' number, top left x, top left y, colour, size (1, 2 or 3) local i as integer if w < 0 then w = 0 if w > 3 then w = 3 if w = 0 then T18.frect(x, y, 10, 15, black) else T18.frect(x, y, 20*w, 30*w, black) end if select case v case 0 for i = 1 to 6 drawSegment(i, x , y , rcolour, w ) next i case 1 drawSegment(2, x , y , rcolour, w ) drawSegment(3, x , y , rcolour, w) case 2 drawSegment(1, x , y , rcolour, w ) drawSegment(2, x , y , rcolour, w ) drawSegment(4, x , y , rcolour, w ) drawSegment(5, x , y , rcolour, w ) drawSegment(7, x , y , rcolour, w ) case 3 for i = 1 to 4 drawSegment(i, x , y , rcolour, w ) next i drawSegment(7, x , y , rcolour, w ) case 4 drawSegment(2, x , y , rcolour, w ) drawSegment(3, x , y , rcolour, w ) drawSegment(6, x , y , rcolour, w ) drawSegment(7, x , y , rcolour, w ) case 5 drawSegment(1, x , y , rcolour, w ) drawSegment(3, x , y , rcolour, w ) drawSegment(4, x , y , rcolour, w ) drawSegment(6, x , y , rcolour, w ) drawSegment(7, x , y , rcolour, w ) case 6 drawSegment(1, x , y , rcolour, w ) for i = 3 to 7 drawSegment(i, x , y , rcolour, w ) next i case 7 for i = 1 to 3 drawSegment(i, x , y , rcolour, w ) next i case 8 for i = 1 to 8 drawSegment(i, x , y , rcolour, w ) next i case 9 for i = 1 to 4 drawSegment(i, x , y , rcolour, w ) next i drawSegment(6, x , y , rcolour, w ) drawSegment(7, x , y , rcolour, w ) end select end sub sub drawSegment(s as integer, x AS INTEGER, y AS INTEGER, rcolour AS INTEGER, w as integer) if w < 0 then w = 0 if w > 3 then w = 3 if w = 0 then select case s case 1 T18.dline(x+2, y+2, x+8, y+2, rcolour) case 2 T18.dline(x+8, y+2, x+8, y+8, rcolour) case 3 T18.dline(x+8, y+8, x+8, y+14, rcolour) case 4 T18.dline(x+2, y+14, x+8, y+14, rcolour) case 5 T18.dline(x+2, y+8, x+2, y+14, rcolour) case 6 T18.dline(x+2, y+2, x+2, y+8, rcolour) case 7 T18.dline(x+2, y+8, x+8, y+8, rcolour) end select else select case s case 1 T18.frndrect(x+4*w, y+3*w, 12*w, 2*w, w, rcolour) case 2 T18.frndrect(x+15*w, y+4*w, 2*w, 10*w, w, rcolour) case 3 T18.frndrect(x+15*w, y+14*w, 2*w, 10*w, w, rcolour) case 4 T18.frndrect(x+4*w, y+23*w, 12*w, 2*w, w, rcolour) case 5 T18.frndrect(x+3*w, y+14*w, 2*w, 10*w, w, rcolour) case 6 T18.frndrect(x+3*w, y+4*w, 2*w, 10*w, w, rcolour) case 7 T18.frndrect(x+4*w, y+13*w, 12*w, 2*w, w, rcolour) end select end if end sub VK7JH MMedit |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |