7-segment display

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

7-segment display

Post by Henko »

Code: Select all

graphics ! graphics clear ! option base 1 ! fill color 0,.7,0
dim sx(7,6),sy(7,6),num(10,7)
for k=1 to 6 ! for i=1 to 4 ! read sx(k,i),sy(k,i) ! next i ! next k
for i=1 to 6 ! read sx(7,i),sy(7,i) ! next i
for k=1 to 10 ! for j=1 to 7 ! read num(k,j) ! next j ! next k
data 5,0, 75,0, 65,10, 15,10,  0,5, 10,15, 10,69, 0,74
data 80,5, 70,15, 70,69, 80,74,  0,86, 10,91, 10,147, 0,157
data 80,86, 70,91, 70,147, 80,157, 5,160, 75,160, 65,150, 15,150
data 0,80, 10,75, 70,75, 80,80, 70,85, 10,85
data 1,2,3,4,5,6,-1,  3,5,-1,0,0,0,0,  1,3,7,4,6,-1,0
data 1,3,5,6,7,-1,0, 2,7,3,5,-1,0,0,  1,2,7,5,6,-1,0
data 1,2,4,6,5,7,-1, 1,3,5,-1,0,0,0,  1,2,3,4,5,6,7,  1,2,3,7,5,6,-1

for i=0 to 9 ! number (i,20+60*i,50,.5) ! next i
end

' 7-segment number k, left upper corner at x,y screenposition
' sc = scale, scale 1 gives 80x160 size on screen
' 
def number(k,x,y,sc)
fill color 0,0,0 ! fill alpha .7
fill rect x-4,y-4 to 80*sc+x+4,160*sc+y+4
fill color 0,.7,0 ! fill alpha 1
for j=1 to 7
  snum=.num(k+1,j) ! if snum=-1 then break
  segment_on(snum,x,y,sc)
  next j
end def

def segment_on (nr,x,y,sc)
dim xseg(6), yseg(6)
if nr>6 then k=6 else k=4
for i=1 to k ! xseg(i)=sc*.sx(nr,i)+x ! yseg(i)=sc*.sy(nr,i)+y ! next i
fill poly xseg,yseg count k
end def

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: 7-segment display

Post by Mr. Kibernetik »

Very interesting.
You also can use 3rd party TTF font of any style you like to get similar effect.

Post Reply