Seven segment

Oletko tehnyt jotain, mistä muut voisivat hyötyä. Postita vinkit tänne.
Post Reply
User avatar
Koodari
Active Member
Posts: 201
Joined: Wed Nov 18, 2009 9:01 pm
Contact:

Seven segment

Post by Koodari »

Seven segment tarkoittaa 7 segmenttistä ohjailtavaa "ledinumerotaulua"
Tässä esimerkki:

Code: Select all

Repeat
    For numb = 0 To 10
        SegNum(10,10,numb) 'x,y,numb (numb = 0-9 jos erisuuri, niin on tyhjä!)
        DrawScreen
        Wait 1000
    Next numb
Forever

Function SegNum(x,y,numb)
    Color cbDark
    Line x+3,y,x+17,y
    Line x+2,y+1,x+18,y+1
    Line x+3,y+2,x+17,y+2
    Line x+4,y+3,x+16,y+3
    Line x+17,y+4,x+17,y+16
    Line x+18,y+3,x+18,y+17
    Line x+19,y+2,x+19,y+18
    Line x+20,y+3,x+20,y+17
    Line x+17,y+21,x+17,y+33
    Line x+18,y+20,x+18,y+34
    Line x+19,y+19,x+19,y+35
    Line x+20,y+20,x+20,y+34
    Line x+4,y+34,x+16,y+34
    Line x+3,y+35,x+17,y+35
    Line x+2,y+36,x+18,y+36
    Line x+3,y+37,x+17,y+37
    Line x,y+20,x,y+34
    Line x+1,y+19,x+1,y+35
    Line x+2,y+20,x+2,y+34
    Line x+3,y+21,x+3,y+33
    Line x,y+3,x,y+17
    Line x+1,y+2,x+1,y+18
    Line x+2,y+3,x+2,y+17
    Line x+3,y+4,x+3,y+16
    Line x+4,y+17,x+16,y+17
    Line x+3,y+18,x+17,y+18
    Line x+3,y+19,x+17,y+19
    Line x+4,y+20,x+16,y+20
    Color cbGreen
    Select numb
        Case 0
            s1 = 1
            s2 = 1
            s3 = 1
            s4 = 1
            s5 = 1
            s6 = 1
            s7 = 0
        Case 1
            s1 = 0
            s2 = 1
            s3 = 1
            s4 = 0
            s5 = 0
            s6 = 0
            s7 = 0
        Case 2
            s1 = 1
            s2 = 1
            s3 = 0
            s4 = 1
            s5 = 1
            s6 = 0
            s7 = 1
        Case 3
            s1 = 1
            s2 = 1
            s3 = 1
            s4 = 1
            s5 = 0
            s6 = 0
            s7 = 1
        Case 4
            s1 = 0
            s2 = 1
            s3 = 1
            s4 = 0
            s5 = 0
            s6 = 1
            s7 = 1
        Case 5
            s1 = 1
            s2 = 0
            s3 = 1
            s4 = 1
            s5 = 0
            s6 = 1
            s7 = 1
        Case 6
            s1 = 1
            s2 = 0
            s3 = 1
            s4 = 1
            s5 = 1
            s6 = 1
            s7 = 1
        Case 7
            s1 = 1
            s2 = 1
            s3 = 1
            s4 = 0
            s5 = 0
            s6 = 0
            s7 = 0
        Case 8
            s1 = 1
            s2 = 1
            s3 = 1
            s4 = 1
            s5 = 1
            s6 = 1
            s7 = 1
        Case 9
            s1 = 1
            s2 = 1
            s3 = 1
            s4 = 1
            s5 = 0
            s6 = 1
            s7 = 1
        Default
            s1 = 0
            s2 = 0
            s3 = 0
            s4 = 0
            s5 = 0
            s6 = 0
            s7 = 0
    EndSelect
    If s1 = 1 Then
        Line x+3,y,x+17,y
        Line x+2,y+1,x+18,y+1
        Line x+3,y+2,x+17,y+2
        Line x+4,y+3,x+16,y+3
    EndIf
    If s2 = 1 Then
        Line x+17,y+4,x+17,y+16
        Line x+18,y+3,x+18,y+17
        Line x+19,y+2,x+19,y+18
        Line x+20,y+3,x+20,y+17
    EndIf
    If s3 = 1 Then
        Line x+17,y+21,x+17,y+33
        Line x+18,y+20,x+18,y+34
        Line x+19,y+19,x+19,y+35
        Line x+20,y+20,x+20,y+34
    EndIf
    If s4 = 1 Then
        Line x+4,y+34,x+16,y+34
        Line x+3,y+35,x+17,y+35
        Line x+2,y+36,x+18,y+36
        Line x+3,y+37,x+17,y+37
    EndIf
    If s5 = 1 Then
        Line x,y+20,x,y+34
        Line x+1,y+19,x+1,y+35
        Line x+2,y+20,x+2,y+34
        Line x+3,y+21,x+3,y+33
    EndIf
    If s6 = 1 Then
        Line x,y+3,x,y+17
        Line x+1,y+2,x+1,y+18
        Line x+2,y+3,x+2,y+17
        Line x+3,y+4,x+3,y+16
    EndIf
    If s7 = 1 Then
        Line x+4,y+17,x+16,y+17
        Line x+3,y+18,x+17,y+18
        Line x+3,y+19,x+17,y+19
        Line x+4,y+20,x+16,y+20
    EndIf
EndFunction
Alussa oli asiakas, projekti ja Koodari...

Code: Select all

[23:36:33] <Minixmix> jos nyt viel yhen lastin heittäis
[23:36:48] <Minixmix> Sit loput vois hoitaa kännyllä :/
[00:14:49] <Minixmix> mutta nyt tyhjennykselle ->
[/size]
DJ-Filbe
Devoted Member
Posts: 854
Joined: Sat Feb 20, 2010 2:18 pm

Re: Seven segment

Post by DJ-Filbe »

Katos katos! Suunnittelin ite tekeväni tollasia mut sit en vissiin jaksanu niin tein tällasen
EDIT:

Fiksasin systeemiä hiukan, ohjelma käyttää nyt vähemmän muuttujia ja koodia. Tein tuohon heksa-ominaisuudenkin, eli mukaan tulee myös merkit A,B,C,D,E ja F.

Code: Select all

Dim numb(10)
Repeat
    For numb1 = 0 To 15
    For numb2 = 0 To 15
    For numb3 = 0 To 15
    For numb4 = 0 To 15
    For numb5 = 0 To 15
    For numb6 = 0 To 15
    For numb7 = 0 To 15
    For numb8 = 0 To 15
    For numb9 = 0 To 15
    For numb10 = 0 To 15
        
            Segnum(30,10,numb1)
            Segnum(60,10,numb2)
            Segnum(90,10,numb3)
            Segnum(120,10,numb4)
            Segnum(150,10,numb5)
            Segnum(180,10,numb6)
            Segnum(210,10,numb7)
            Segnum(240,10,numb8)
            Segnum(270,10,numb9)
            Segnum(300,10,numb10)
            
        DrawScreen
    Next numb10
    Next numb9
    Next numb8
    Next numb7
    Next numb6
    Next numb5
    Next numb4
    Next numb3
    Next numb2  
    Next numb1

Forever

Function SegNum(x,y,num)
        Color cbDark
        Line x+3,y,x+17,y
        Line x+2,y+1,x+18,y+1
        Line x+3,y+2,x+17,y+2
        Line x+4,y+3,x+16,y+3
        Line x+17,y+4,x+17,y+16
        Line x+18,y+3,x+18,y+17
        Line x+19,y+2,x+19,y+18
        Line x+20,y+3,x+20,y+17
        Line x+17,y+21,x+17,y+33
        Line x+18,y+20,x+18,y+34
        Line x+19,y+19,x+19,y+35
        Line x+20,y+20,x+20,y+34
        Line x+4,y+34,x+16,y+34
        Line x+3,y+35,x+17,y+35
        Line x+2,y+36,x+18,y+36
        Line x+3,y+37,x+17,y+37
        Line x,y+20,x,y+34
        Line x+1,y+19,x+1,y+35
        Line x+2,y+20,x+2,y+34
        Line x+3,y+21,x+3,y+33
        Line x,y+3,x,y+17
        Line x+1,y+2,x+1,y+18
        Line x+2,y+3,x+2,y+17
        Line x+3,y+4,x+3,y+16
        Line x+4,y+17,x+16,y+17
        Line x+3,y+18,x+17,y+18
        Line x+3,y+19,x+17,y+19
        Line x+4,y+20,x+16,y+20
        Line x+5,y+8,x+5,y+12
        Line x+6,y+7,x+6,y+13
        Line x+7,y+8,x+7,y+12
        Line x+8,y+9,x+8,y+11
        Line x+5,y+25,x+5,y+29
        Line x+6,y+14,x+6,y+30
        Line x+7,y+25,x+7,y+29
        Line x+8,y+26,x+8,y+28
        Color cbGreen
        s$=""
        Select num
            Case 0, False
                s="111111000"
            Case 1
                s="011000000"
            Case 2
                s="110110100"
            Case 3
                s="111100100"
            Case 4
                s="011001100"
            Case 5
                s="101101100"
            Case 6
                s="101111100"
            Case 7
                s="111000000"
            Case 8
                s="111111100"
            Case 9
                s="111101100"
            Case 10
            s="111011100"
            Case 11
            s="111100111"
            Case 12
            s="100111000"
            Case 13
            s="111100011"
            Case 14
            s="100111100"
            Case 15
            s="100011100"
            Default
                s="11111100"
        EndSelect
        If Mid(s,1,1) = "1" Then
            Line x+3,y,x+17,y
            Line x+2,y+1,x+18,y+1
            Line x+3,y+2,x+17,y+2
            Line x+4,y+3,x+16,y+3
        EndIf
        If Mid(s,2,1) = "1" Then
            Line x+17,y+4,x+17,y+16
            Line x+18,y+3,x+18,y+17
            Line x+19,y+2,x+19,y+18
            Line x+20,y+3,x+20,y+17
        EndIf
        If Mid(s,3,1) = "1" Then
            Line x+17,y+21,x+17,y+33
            Line x+18,y+20,x+18,y+34
            Line x+19,y+19,x+19,y+35
            Line x+20,y+20,x+20,y+34
        EndIf
        If Mid(s,4,1) = "1" Then
            Line x+4,y+34,x+16,y+34
            Line x+3,y+35,x+17,y+35
            Line x+2,y+36,x+18,y+36
            Line x+3,y+37,x+17,y+37
        EndIf
        If Mid(s,5,1) = "1" Then
            Line x,y+20,x,y+34
            Line x+1,y+19,x+1,y+35
            Line x+2,y+20,x+2,y+34
            Line x+3,y+21,x+3,y+33
        EndIf
        If Mid(s,6,1) = "1" Then
            Line x,y+3,x,y+17
            Line x+1,y+2,x+1,y+18
            Line x+2,y+3,x+2,y+17
            Line x+3,y+4,x+3,y+16
        EndIf
        If Mid(s,7,1) = "1" Then
            Line x+4,y+17,x+16,y+17
            Line x+3,y+18,x+17,y+18
            Line x+3,y+19,x+17,y+19
            Line x+4,y+20,x+16,y+20
        EndIf
        If Mid(s,8,1) = "1" Then
            Line x+5,y+8,x+5,y+12
            Line x+6,y+7,x+6,y+13
            Line x+7,y+8,x+7,y+12
            Line x+8,y+9,x+8,y+11
        EndIf
        If Mid(s,9,1) = "1" Then
            Line x+5,y+25,x+5,y+29
            Line x+6,y+14,x+6,y+30
            Line x+7,y+25,x+7,y+29
            Line x+8,y+26,x+8,y+28
        EndIf
EndFunction
Attachments
a.png
a.png (21.07 KiB) Viewed 4960 times
User avatar
valscion
Moderator
Moderator
Posts: 1599
Joined: Thu Dec 06, 2007 7:46 pm
Location: Espoo
Contact:

Re: Seven segment

Post by valscion »

DJ-Nerd wrote:
EDIT:

Fiksasin systeemiä hiukan, ohjelma käyttää nyt vähemmän muuttujia ja koodia. Tein tuohon heksa-ominaisuudenkin, eli mukaan tulee myös merkit A,B,C,D,E ja F.

Mielestäni näyttää rumemmalta, kun heksaa varten tarvittavat pallukat lisätään tuohon. Kyllä 0-9 riittää mielestäni ihan hyvin. Voihan sinne jotain omia säätöjä sitten keksiä, mutta ilman uusia paikkoja ;) esim. h-kirjaimen saisi muodostettua helposti.

Tein nopeustestin, että kumpi tapa on nopeampi, käyttää merkkijonoja vai listata jokainen kohta omaan muuttujaansa. Kyllä se jokainen-omaan-muuttujaan tapa oli muutamia millisekunteja nopeampi, mutta ero ei ollut todellakaan iso (1666ms-1670ms, kun rullattiin numerot 00-99). Tuota voisi vielä optimoida niin, että säästyisi turhilta piirtokomennoilta kun piirtäisi vain ne tummat laatikot, joissa ei ole "valoa". Näin siis itse tekisin:

Code: Select all

// Pikku nopeustesti tässä vielä :P
Locate 0,100

For iteration = 1 To 10

start = Timer()

For numb1 = 0 To 9
For numb2 = 0 To 9
   
    Segnum(30,10,numb1)
    Segnum(60,10,numb2)
      
    DrawScreen

Next numb2 
Next numb1

AddText "Aikaa kului "+(Timer()-start)+"ms."

Next iteration

Repeat
    DrawScreen OFF
    key=WaitKey()
Until key=cbKeyReturn Or key=cbKeyEnter

ScreenShot GetEXEName()+".bmp"
End

Function SegNum(x,y,numb)
    Select numb
        Case 0
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 1 : s5 = 1 : s6 = 1 : s7 = 0
        Case 1
            s1 = 0 : s2 = 1 : s3 = 1 : s4 = 0 : s5 = 0 : s6 = 0 : s7 = 0
        Case 2
            s1 = 1 : s2 = 1 : s3 = 0 : s4 = 1 : s5 = 1 : s6 = 0 : s7 = 1
        Case 3
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 1 : s5 = 0 : s6 = 0 : s7 = 1
        Case 4
            s1 = 0 : s2 = 1 : s3 = 1 : s4 = 0 : s5 = 0 : s6 = 1 : s7 = 1
        Case 5
            s1 = 1 : s2 = 0 : s3 = 1 : s4 = 1 : s5 = 0 : s6 = 1 : s7 = 1
        Case 6
            s1 = 1 : s2 = 0 : s3 = 1 : s4 = 1 : s5 = 1 : s6 = 1 : s7 = 1
        Case 7
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 0 : s5 = 0 : s6 = 0 : s7 = 0
        Case 8
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 1 : s5 = 1 : s6 = 1 : s7 = 1
        Case 9
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 1 : s5 = 0 : s6 = 1 : s7 = 1
        Default
            s1 = 0 : s2 = 0 : s3 = 0 : s4 = 0 : s5 = 0 : s6 = 0 : s7 = 0
    EndSelect

    If s1 Then Color cbGreen Else Color cbDark
    Line x+3,y,x+17,y
    Line x+2,y+1,x+18,y+1
    Line x+3,y+2,x+17,y+2
    Line x+4,y+3,x+16,y+3
    
    If s2 Then Color cbGreen Else Color cbDark
    Line x+17,y+4,x+17,y+16
    Line x+18,y+3,x+18,y+17
    Line x+19,y+2,x+19,y+18
    Line x+20,y+3,x+20,y+17
    
    If s3 Then Color cbGreen Else Color cbDark
    Line x+17,y+21,x+17,y+33
    Line x+18,y+20,x+18,y+34
    Line x+19,y+19,x+19,y+35
    Line x+20,y+20,x+20,y+34
    
    If s4 Then Color cbGreen Else Color cbDark
    Line x+4,y+34,x+16,y+34
    Line x+3,y+35,x+17,y+35
    Line x+2,y+36,x+18,y+36
    Line x+3,y+37,x+17,y+37
    
    If s5 Then Color cbGreen Else Color cbDark
    Line x,y+20,x,y+34
    Line x+1,y+19,x+1,y+35
    Line x+2,y+20,x+2,y+34
    Line x+3,y+21,x+3,y+33

    If s6 Then Color cbGreen Else Color cbDark
    Line x,y+3,x,y+17
    Line x+1,y+2,x+1,y+18
    Line x+2,y+3,x+2,y+17
    Line x+3,y+4,x+3,y+16
    
    If s7 Then Color cbGreen Else Color cbDark
    Line x+4,y+17,x+16,y+17
    Line x+3,y+18,x+17,y+18
    Line x+3,y+19,x+17,y+19
    Line x+4,y+20,x+16,y+20
EndFunction 
EDIT: Fiksasin vähän koodia.
cbEnchanted, uudelleenkirjoitettu runtime. Uusin versio: 0.4.1 — Nyt myös sorsat GitHubissa!
NetMatch - se kunnon nettimättö-deathmatch! Avoimella lähdekoodilla varustettu
vesalaakso.com
DJ-Filbe
Devoted Member
Posts: 854
Joined: Sat Feb 20, 2010 2:18 pm

Re: Seven segment

Post by DJ-Filbe »

Kyllä kyllä, onhan tuo nopeampi, mutta mielestäni on kätevämpää esittää merkkijonona kun kymmenenä numeromuuttujana. Ja noi mun omat 2 lisäpaikkaa... njoo :oops: en oo niin kovin hyvä hahmottamaan miten olisin saanut samantapaisen 8. ja 9. paikan kuin niiden isommat versionsa oli.
EDIT:

Sitäpaitsi eivätkö ne lisäpaikat olisikin normaalisti tuon systeemin ulkoreunalla?

MaGetzUb
Guru
Posts: 1715
Joined: Sun Sep 09, 2007 12:35 pm
Location: Alavus

Re: Seven segment

Post by MaGetzUb »

Hmm.. En tiedä sitten mitä ajatte takaa monella sisäisellä For..Next silmukalla, mutta näinkin voi tehdä ihan iisisti myös:

Code: Select all

x = 1024
Repeat
    x = x + 1
 
    For i = 1 To Len(Str(x))
        SegNum(10+i*25, 20, Mid(Str(x), i, 1))
    Next i
    DrawScreen
Forever 


Function SegNum(x,y,numb)
    Select numb
        Case 0
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 1 : s5 = 1 : s6 = 1 : s7 = 0
        Case 1
            s1 = 0 : s2 = 1 : s3 = 1 : s4 = 0 : s5 = 0 : s6 = 0 : s7 = 0
        Case 2
            s1 = 1 : s2 = 1 : s3 = 0 : s4 = 1 : s5 = 1 : s6 = 0 : s7 = 1
        Case 3
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 1 : s5 = 0 : s6 = 0 : s7 = 1
        Case 4
            s1 = 0 : s2 = 1 : s3 = 1 : s4 = 0 : s5 = 0 : s6 = 1 : s7 = 1
        Case 5
            s1 = 1 : s2 = 0 : s3 = 1 : s4 = 1 : s5 = 0 : s6 = 1 : s7 = 1
        Case 6
            s1 = 1 : s2 = 0 : s3 = 1 : s4 = 1 : s5 = 1 : s6 = 1 : s7 = 1
        Case 7
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 0 : s5 = 0 : s6 = 0 : s7 = 0
        Case 8
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 1 : s5 = 1 : s6 = 1 : s7 = 1
        Case 9
            s1 = 1 : s2 = 1 : s3 = 1 : s4 = 1 : s5 = 0 : s6 = 1 : s7 = 1
        Default
            s1 = 0 : s2 = 0 : s3 = 0 : s4 = 0 : s5 = 0 : s6 = 0 : s7 = 0
    EndSelect

    If s1 Then Color cbGreen Else Color cbDark
    Line x+3,y,x+17,y
    Line x+2,y+1,x+18,y+1
    Line x+3,y+2,x+17,y+2
    Line x+4,y+3,x+16,y+3
    
    If s2 Then Color cbGreen Else Color cbDark
    Line x+17,y+4,x+17,y+16
    Line x+18,y+3,x+18,y+17
    Line x+19,y+2,x+19,y+18
    Line x+20,y+3,x+20,y+17
    
    If s3 Then Color cbGreen Else Color cbDark
    Line x+17,y+21,x+17,y+33
    Line x+18,y+20,x+18,y+34
    Line x+19,y+19,x+19,y+35
    Line x+20,y+20,x+20,y+34
    
    If s4 Then Color cbGreen Else Color cbDark
    Line x+4,y+34,x+16,y+34
    Line x+3,y+35,x+17,y+35
    Line x+2,y+36,x+18,y+36
    Line x+3,y+37,x+17,y+37
    
    If s5 Then Color cbGreen Else Color cbDark
    Line x,y+20,x,y+34
    Line x+1,y+19,x+1,y+35
    Line x+2,y+20,x+2,y+34
    Line x+3,y+21,x+3,y+33

    If s6 Then Color cbGreen Else Color cbDark
    Line x,y+3,x,y+17
    Line x+1,y+2,x+1,y+18
    Line x+2,y+3,x+2,y+17
    Line x+3,y+4,x+3,y+16
    
    If s7 Then Color cbGreen Else Color cbDark
    Line x+4,y+17,x+16,y+17
    Line x+3,y+18,x+17,y+18
    Line x+3,y+19,x+17,y+19
    Line x+4,y+20,x+16,y+20
EndFunction
Tein tuon VezQn koodista.
Solar Eclipse
Meneillä olevat Projektit:
We're in a simulation, and God is trying to debug us.
Post Reply