Page 1 sur 1

Gadget Afficheur 7 Segments

Publié : mer. 01/juin/2005 20:45
par Droopy
Création facile d'afficheur 7 segments

Code : Tout sélectionner

; PureBasic 3.93 
; Idea from Localmotion34 

; De préférence utilisez un gadget ayant un rapport de 11 * 13 ex 110 / 130

Structure SevenSegmentLed 
  x.l 
  y.l 
  width.l 
  height.l 
  Image.l 
  Gadget.l 
  value.l
  point.l
  color1.l 
  color2.l 
  BackgroundColor.l
EndStructure 

;{ Datasection
DataSection
Led:
; Segment a
Data.l 1,1,1,-1,6,0,1,1,-1,1,-6,0,-1,-1,0,0
; Segment g
Data.l 1,6,1,-1,6,0,1,1,-1,1,-6,0,-1,-1,0,0
; Segment d
Data.l 1,11,1,-1,6,0,1,1,-1,1,-6,0,-1,-1,0,0
; Segment f
Data.l 1,1,1,1,0,3,-1,1,-1,-1,0,-3,1,-1,0,0
; Segment b
Data.l 9,1,1,1,0,3,-1,1,-1,-1,0,-3,1,-1,0,0
; Segment e
Data.l 1,6,1,1,0,3,-1,1,-1,-1,0,-3,1,-1,0,0
; Segment c
Data.l 9,6,1,1,0,3,-1,1,-1,-1,0,-3,1,-1,0,0
; Point
Data.l 10,11,1,1,-1,1,-1,-1,1,-1,0,0
; Fin dessin Leds
Data.l 0,0

SegmentA:
Data.l 5,1
SegmentB:
Data.l 9,3
SegmentC:
Data.l 9,8
SegmentD:
Data.l 5,11
SegmentE:
Data.l 1,9
SegmentF:
Data.l 1,4
SegmentG:
Data.l 5,6
SegmentP:
Data.l 10,12

EndDataSection
;}

ProcedureDLL SevenSegmentLed(x,y,width,height,color1,color2,BackgroundColor) 
  
  ; Initialise the LinkedList the first call 
  Static Init 
  If Init=0 
    NewList SevenSegmentLedLList.SevenSegmentLed() 
  EndIf 
  Init=1 
  
  ; Fill the Structure 
  AddElement(SevenSegmentLedLList()) 
  SevenSegmentLedLList()\x=x 
  SevenSegmentLedLList()\y=y 
  SevenSegmentLedLList()\width=width 
  SevenSegmentLedLList()\height=height 
  SevenSegmentLedLList()\color1=color1 
  SevenSegmentLedLList()\color2=color2 
  SevenSegmentLedLList()\BackgroundColor=BackgroundColor
  SevenSegmentLedLList()\Image=CreateImage(#PB_Any,width,height) 
  
  PWidth.f=SevenSegmentLedLList()\width/11
  PHeight.f=SevenSegmentLedLList()\height/13
  
  
  ;/ Dessine les Leds
  UseImage(SevenSegmentLedLList()\Image)
  StartDrawing(ImageOutput())
  Box(0,0,SevenSegmentLedLList()\width,SevenSegmentLedLList()\height,SevenSegmentLedLList()\BackgroundColor)
  Restore  Led
  Repeat
    Read x
    Read y
    If x=0 And y=0 : Break : EndIf
    Repeat
      Read a
      Read b
      If a=0 And b=0 : Break : EndIf
      Line(x*PWidth,y*PHeight,a*PWidth,b*PHeight,color1)
      x=x+a : y=y+b
    ForEver
  ForEver
  StopDrawing()
  
  ; create the gadget & show the image 
  SevenSegmentLedLList()\Gadget=ImageGadget(#PB_Any,SevenSegmentLedLList()\x,SevenSegmentLedLList()\y,width,height,UseImage(SevenSegmentLedLList()\Image),#PB_Image_Border) 
  
  ; Return the gadget id 
  ProcedureReturn ListIndex(SevenSegmentLedLList()) 
  
EndProcedure 

ProcedureDLL SevenSegmentLedSet(id,value) 
  
  SelectElement(SevenSegmentLedLList(),id) 
  
  SevenSegmentLedLList()\value=value 
  
  PWidth.f=SevenSegmentLedLList()\width/11
  PHeight.f=SevenSegmentLedLList()\height/13
  
  ;/ Allume les Segments
  UseImage(SevenSegmentLedLList()\Image)
  StartDrawing(ImageOutput())
  
  ; Eteind les segments
  Restore SegmentA
  For n=1 To 8
    Read a
    Read b
    FillArea(a*PWidth,b*PHeight,SevenSegmentLedLList()\color1,SevenSegmentLedLList()\BackgroundColor)
  Next
  
  Select value
    Case 0
      temp.s="abcdef"
    Case 1
      temp="bc"
    Case 2
      temp="abged"
    Case 3
      temp="abgcd"
    Case 4
      temp="fbgc"
    Case 5
      temp="afgcd"
    Case 6
      temp="afedgc"
    Case 7
      temp="abc"
    Case 8
      temp="abcdefg"
    Case 9
      temp="abcdfg"
  EndSelect
  
  ; Gestion du point
  If SevenSegmentLedLList()\point=1
    temp+"p"
  EndIf
  
  
  For n=1 To Len(temp)
    Select Mid(temp,n,1)
      Case "a"
        Restore SegmentA
      Case "b"
        Restore SegmentB
      Case "c"
        Restore SegmentC
      Case "d"
        Restore SegmentD
      Case "e"
        Restore SegmentE
      Case "f"
        Restore SegmentF
      Case "g"
        Restore SegmentG
      Case "p"
        Restore SegmentP
     
    EndSelect
    
    
    Read a
    Read b
    
    FillArea(a*PWidth,b*PHeight,SevenSegmentLedLList()\color1,SevenSegmentLedLList()\color2)
  Next
  
    StopDrawing()
      
  SetGadgetState(SevenSegmentLedLList()\Gadget,UseImage(SevenSegmentLedLList()\Image)) 
  
EndProcedure 

ProcedureDLL SevenSegmentLedGet(id) 
  SelectElement(SevenSegmentLedLList(),id) 
  ProcedureReturn SevenSegmentLedLList()\value 
EndProcedure 

Procedure SevenSegmentLedEvent(id) 
  SelectElement(SevenSegmentLedLList(),id) 
  ProcedureReturn SevenSegmentLedLList()\Gadget 
EndProcedure  

Procedure SevenSegmentLedPoint(id,light)
  SelectElement(SevenSegmentLedLList(),id) 
  SevenSegmentLedLList()\point=light
EndProcedure



;/ Test 
OpenWindow(0,0,0,580,290,#PB_Window_SystemMenu|#PB_Window_ScreenCentered ,"7 Segment Led")
CreateGadgetList(WindowID(0))
SevenSegmentLed(10,10,220,260,8404992,16776960,10485760)
SevenSegmentLed(250,10,110,130,4227072,65280,4210688)
SevenSegmentLed(400,10,55,65,1118481,255,0)
SevenSegmentLed(455,10,55,65,1118481,255,0)
SevenSegmentLed(510,10,55,65,1118481,255,0)

For n= 0 To 9
  For i=1 To 4
    SevenSegmentLedSet(i,Random(9))
    SevenSegmentLedPoint(i,Random(1))
  Next i 
  
  SevenSegmentLedSet(0,n)
  
  Beep_(1000,25)
  Delay(500)
Next n

Publié : mer. 01/juin/2005 21:27
par Backup
cool ! :D

Publié : mer. 01/juin/2005 22:17
par nico
Vraiment bien. :D

Publié : jeu. 02/juin/2005 8:04
par bernard13
Trop fort le Droopy

Publié : jeu. 02/juin/2005 12:22
par Anonyme2
Très bon 8)

Publié : jeu. 02/juin/2005 13:05
par Good07
Je dirais même plus super Cool ! :D

Publié : jeu. 02/juin/2005 14:56
par Dr. Dri
un afficheur 7 segments ^^
tu me prend par les entiments là ^^

tu gère pas l'hexa avec ???

Dri

Publié : jeu. 02/juin/2005 15:13
par Droopy
Si ça t'interesse je peut rajouter les codes pour afficher de l'hexa

juste quelques data à rajouter ...

Publié : jeu. 02/juin/2005 17:33
par Droopy
Voici une version qui gère les digit hexa

Code : Tout sélectionner

; PureBasic 3.93 
; Idea from Localmotion34 

; De préférence utilisez un gadget ayant un rapport de 11 * 13 ex 110 / 130

Structure SevenSegmentLed 
  x.l 
  y.l 
  width.l 
  height.l 
  Image.l 
  Gadget.l 
  value.l
  point.l
  color1.l 
  color2.l 
  BackgroundColor.l
EndStructure 

;{ Datasection
DataSection
Led:
; Segment a
Data.l 1,1,1,-1,6,0,1,1,-1,1,-6,0,-1,-1,0,0
; Segment g
Data.l 1,6,1,-1,6,0,1,1,-1,1,-6,0,-1,-1,0,0
; Segment d
Data.l 1,11,1,-1,6,0,1,1,-1,1,-6,0,-1,-1,0,0
; Segment f
Data.l 1,1,1,1,0,3,-1,1,-1,-1,0,-3,1,-1,0,0
; Segment b
Data.l 9,1,1,1,0,3,-1,1,-1,-1,0,-3,1,-1,0,0
; Segment e
Data.l 1,6,1,1,0,3,-1,1,-1,-1,0,-3,1,-1,0,0
; Segment c
Data.l 9,6,1,1,0,3,-1,1,-1,-1,0,-3,1,-1,0,0
; Point
Data.l 10,11,1,1,-1,1,-1,-1,1,-1,0,0
; Fin dessin Leds
Data.l 0,0

SegmentA:
Data.l 5,1
SegmentB:
Data.l 9,3
SegmentC:
Data.l 9,8
SegmentD:
Data.l 5,11
SegmentE:
Data.l 1,9
SegmentF:
Data.l 1,4
SegmentG:
Data.l 5,6
SegmentP:
Data.l 10,12

EndDataSection
;}

ProcedureDLL SevenSegmentLed(x,y,width,height,color1,color2,BackgroundColor) 
  
  ; Initialise the LinkedList the first call 
  Static Init 
  If Init=0 
    NewList SevenSegmentLedLList.SevenSegmentLed() 
  EndIf 
  Init=1 
  
  ; Fill the Structure 
  AddElement(SevenSegmentLedLList()) 
  SevenSegmentLedLList()\x=x 
  SevenSegmentLedLList()\y=y 
  SevenSegmentLedLList()\width=width 
  SevenSegmentLedLList()\height=height 
  SevenSegmentLedLList()\color1=color1 
  SevenSegmentLedLList()\color2=color2 
  SevenSegmentLedLList()\BackgroundColor=BackgroundColor
  SevenSegmentLedLList()\Image=CreateImage(#PB_Any,width,height) 
  
  PWidth.f=SevenSegmentLedLList()\width/11
  PHeight.f=SevenSegmentLedLList()\height/13
  
  
  ;/ Dessine les Leds
  UseImage(SevenSegmentLedLList()\Image)
  StartDrawing(ImageOutput())
  Box(0,0,SevenSegmentLedLList()\width,SevenSegmentLedLList()\height,SevenSegmentLedLList()\BackgroundColor)
  Restore  Led
  Repeat
    Read x
    Read y
    If x=0 And y=0 : Break : EndIf
    Repeat
      Read a
      Read b
      If a=0 And b=0 : Break : EndIf
      Line(x*PWidth,y*PHeight,a*PWidth,b*PHeight,color1)
      x=x+a : y=y+b
    ForEver
  ForEver
  StopDrawing()
  
  ; create the gadget & show the image 
  SevenSegmentLedLList()\Gadget=ImageGadget(#PB_Any,SevenSegmentLedLList()\x,SevenSegmentLedLList()\y,width,height,UseImage(SevenSegmentLedLList()\Image),#PB_Image_Border) 
  
  ; Return the gadget id 
  ProcedureReturn ListIndex(SevenSegmentLedLList()) 
  
EndProcedure 

ProcedureDLL SevenSegmentLedSet(id,value) 
  
  SelectElement(SevenSegmentLedLList(),id) 
  
  SevenSegmentLedLList()\value=value 
  
  PWidth.f=SevenSegmentLedLList()\width/11
  PHeight.f=SevenSegmentLedLList()\height/13
  
  ;/ Allume les Segments
  UseImage(SevenSegmentLedLList()\Image)
  StartDrawing(ImageOutput())
  
  ; Eteind les segments
  Restore SegmentA
  For n=1 To 8
    Read a
    Read b
    FillArea(a*PWidth,b*PHeight,SevenSegmentLedLList()\color1,SevenSegmentLedLList()\BackgroundColor)
  Next
  
  Select value
    Case 0
      temp.s="abcdef"
    Case 1
      temp="bc"
    Case 2
      temp="abged"
    Case 3
      temp="abgcd"
    Case 4
      temp="fbgc"
    Case 5
      temp="afgcd"
    Case 6
      temp="afedgc"
    Case 7
      temp="abc"
    Case 8
      temp="abcdefg"
    Case 9
      temp="abcdfg"
    Case 10 ; A
      temp="abcefg"
    Case 11 ; b
      temp="fgcde"
    Case 12 ; c
      temp="ged"
    Case 13 ; d
      temp="bcdeg"
    Case 14 ; E
      temp="afged"
    Case 15 ; F
      temp="afeg"
      
      
      
  EndSelect
  
  
  ; Gestion du point
  If SevenSegmentLedLList()\point=1
    temp+"p"
  EndIf
  
  
  For n=1 To Len(temp)
    Select Mid(temp,n,1)
      Case "a"
        Restore SegmentA
      Case "b"
        Restore SegmentB
      Case "c"
        Restore SegmentC
      Case "d"
        Restore SegmentD
      Case "e"
        Restore SegmentE
      Case "f"
        Restore SegmentF
      Case "g"
        Restore SegmentG
      Case "p"
        Restore SegmentP
     
    EndSelect
    
    
    Read a
    Read b
    
    FillArea(a*PWidth,b*PHeight,SevenSegmentLedLList()\color1,SevenSegmentLedLList()\color2)
  Next
  
    StopDrawing()
      
  SetGadgetState(SevenSegmentLedLList()\Gadget,UseImage(SevenSegmentLedLList()\Image)) 
  
EndProcedure 

ProcedureDLL SevenSegmentLedGet(id) 
  SelectElement(SevenSegmentLedLList(),id) 
  ProcedureReturn SevenSegmentLedLList()\value 
EndProcedure 

ProcedureDLL SevenSegmentLedEvent(id) 
  SelectElement(SevenSegmentLedLList(),id) 
  ProcedureReturn SevenSegmentLedLList()\Gadget 
EndProcedure  

ProcedureDLL SevenSegmentLedPoint(id,light)
  SelectElement(SevenSegmentLedLList(),id) 
  SevenSegmentLedLList()\point=light
EndProcedure



;/ Test 
OpenWindow(0,0,0,580,290,#PB_Window_SystemMenu|#PB_Window_ScreenCentered ,"7 Segment Led")
CreateGadgetList(WindowID(0))
SevenSegmentLed(10,10,220,260,8404992,16776960,10485760)
SevenSegmentLed(250,10,110,130,4227072,65280,4210688)
SevenSegmentLed(400,10,55,65,1118481,255,0)
SevenSegmentLed(455,10,55,65,1118481,255,0)
SevenSegmentLed(510,10,55,65,1118481,255,0)

For n= 0 To 15
  For i=1 To 4
    SevenSegmentLedSet(i,Random(9))
    SevenSegmentLedPoint(i,Random(1))
  Next i 
  
  SevenSegmentLedSet(0,n)
  
  Beep_(1000,25)
  Delay(500)
Next n

Publié : ven. 03/juin/2005 9:51
par Dr. Dri
cool :D
mais le 'C' serait mieux en majuscule ;)

Dri

Publié : ven. 03/juin/2005 10:51
par Droopy
Pour le C en majuscule

Code : Tout sélectionner

Case 12 ; c 
temp="adef"