Welcome to Dream.In.Code
Become a VB Expert!

Join 149,916 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,110 people online right now. Registration is fast and FREE... Join Now!




Seven Segment Counter

 
Reply to this topicStart new topic

Seven Segment Counter

Skisy
22 Dec, 2007 - 03:22 AM
Post #1

New D.I.C Head
*

Joined: 22 Dec, 2007
Posts: 2

Using VB 6:

Hi I'm having a bit of trouble with this, I know what I've got to do (or rather one way of doing it) but I'm struggling with the actual implementation of my thoughts into code.

I've got a seven segment display, and the actual display is sorted more or less (i.e. If I were to create a text box and code, type in a number then it would appear correctly in a seven segment format.) But now I want to make this display act like a timer, where it just counts up on a button click event and stops on a button click event? How would I make it do this?

This is my select case code (in a module) for the display of the seven segment numbers:

CODE
Sub ConvertDigitToLCD(NumberToDisplay As Integer, DigitToChange As Variant)

For n = 0 To 6
    DigitToChange(n).Visible = False
Next n

Select Case NumberToDisplay
      
      Case 0
        DigitToChange(0).Visible = True
        DigitToChange(1).Visible = True
        DigitToChange(2).Visible = True
        DigitToChange(4).Visible = True
        DigitToChange(5).Visible = True
        DigitToChange(6).Visible = True
        
    Case 1
        DigitToChange(2).Visible = True
        DigitToChange(5).Visible = True
        
    Case 2
        DigitToChange(1).Visible = True
        DigitToChange(2).Visible = True
        DigitToChange(3).Visible = True
        DigitToChange(4).Visible = True
        DigitToChange(6).Visible = True
        
    Case 3
        DigitToChange(1).Visible = True
        DigitToChange(2).Visible = True
        DigitToChange(3).Visible = True
        DigitToChange(5).Visible = True
        DigitToChange(6).Visible = True
        
    Case 4
        DigitToChange(0).Visible = True
        DigitToChange(3).Visible = True
        DigitToChange(2).Visible = True
        DigitToChange(5).Visible = True
        
    Case 5
        DigitToChange(0).Visible = True
        DigitToChange(1).Visible = True
        DigitToChange(3).Visible = True
        DigitToChange(5).Visible = True
        DigitToChange(6).Visible = True
        
    Case 6
        DigitToChange(0).Visible = True
        DigitToChange(1).Visible = True
        DigitToChange(3).Visible = True
        DigitToChange(4).Visible = True
        DigitToChange(5).Visible = True
        DigitToChange(6).Visible = True
        
    Case 7
        DigitToChange(1).Visible = True
        DigitToChange(2).Visible = True
        DigitToChange(5).Visible = True
        
    Case 8
        DigitToChange(0).Visible = True
        DigitToChange(1).Visible = True
        DigitToChange(2).Visible = True
        DigitToChange(3).Visible = True
        DigitToChange(4).Visible = True
        DigitToChange(5).Visible = True
        DigitToChange(6).Visible = True
        
    Case 9
        DigitToChange(0).Visible = True
        DigitToChange(1).Visible = True
        DigitToChange(2).Visible = True
        DigitToChange(3).Visible = True
        DigitToChange(5).Visible = True
        DigitToChange(6).Visible = True

End Select

End Sub


I've tested the display a number of ways including using a scroll bar, and this is the code (I've commented out the bits only relevant to the scroll bar) which I've used:


CODE
Private Sub Form_Load()

Dim txtToDisplay As String

'txtToDisplay = "000.00"

'txtToDisplay = Format(HScroll1.Value / 10, "000.00")
ConvertDigitToLCD Mid(txtToDisplay, 1, 1), Digit1
ConvertDigitToLCD Mid(txtToDisplay, 2, 1), Digit2
ConvertDigitToLCD Mid(txtToDisplay, 3, 1), Digit3
'(txtToDisplay, 4, 1) is the decimal point
ConvertDigitToLCD Mid(txtToDisplay, 5, 1), Digit4
ConvertDigitToLCD Mid(txtToDisplay, 6, 1), Digit5

End Sub


I know it's a bit of a lengthy one, but could anyone help me out, or give me more direction? So I can get the code I need and put it in a button click event...I've been thinking I'll need to use a timer, there may be other ways around it though...

Thanks

Skisy.
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Seven Segment Counter
22 Dec, 2007 - 06:07 AM
Post #2

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 4,029



Thanked: 38 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
Add a Timer Control to your form and set it's interval to whatever you wish (unit is ms).
Set its Enabled Property to False.

When the first Command Button is clicked, enable the timer and disable it when the Second Command Button is clicked.

Write another function that returns the current value being displayed by the seven-segment LEDs. (Assuming it is GetValue())

The Timer Function Code would then be something like this:
CODE

Private Sub Timer1_Timer()
ConvertDigitToLCD(GetValue() + 1,  <control_name> )
End Sub


Hope this helps.
smile.gif
User is offlineProfile CardPM
+Quote Post

Skisy
RE: Seven Segment Counter
23 Dec, 2007 - 04:38 AM
Post #3

New D.I.C Head
*

Joined: 22 Dec, 2007
Posts: 2

Excellent, certainly gives me more direction with that.
Thanks for the help! biggrin.gif

This post has been edited by Skisy: 23 Dec, 2007 - 04:39 AM
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Seven Segment Counter
23 Dec, 2007 - 05:17 AM
Post #4

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,280



Thanked: 136 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Just an FYI. I was trying to worry out your truth table. I'm still not sure the logic of, but I came up with something like this:
CODE

Sub ConvertDigitToLCD(n As Integer, DigitToChange As Variant)
    DigitToChange(0).Visible = (n=0) Or (n=4) Or (n=5) Or (n=6) Or (n=8) Or (n=9)
    DigitToChange(1).Visible = (n=0) Or (n=2) Or (n=3) Or (n=5) Or (n=6) Or (n=7) Or (n=8) Or (n=9)
    DigitToChange(2).Visible = (n=0) Or (n=1) Or (n=2) Or (n=3) Or (n=4) Or (n=7) Or (n=8) Or (n=9)
    DigitToChange(3).Visible = (n=2) Or (n=3) Or (n=4) Or (n=5) Or (n=6) Or (n=8) Or (n=9)
    DigitToChange(4).Visible = (n=0) Or (n=2) Or (n=6) Or (n=8)
    DigitToChange(5).Visible = (n=0) Or (n=1) Or (n=2) Or (n=3) Or (n=4) Or (n=5) Or (n=6) Or (n=7) Or (n=8) Or (n=9)
    DigitToChange(6).Visible = (n=0) Or (n=2) Or (n=3) Or (n=5) Or (n=6) Or (n=8) Or (n=9)
End Sub


As I looked at that, I wondered what it would like like if I asserted the negative:

CODE

Sub ConvertDigitToLCD(n As Integer, DigitToChange As Variant)
    DigitToChange(0).Visible = (n<>1) And (n<>2) And (n<>3) And (n<>7)
    DigitToChange(1).Visible = (n<>1) And (n<>4)
    DigitToChange(2).Visible = (n<>5) And (n<>6)
    DigitToChange(3).Visible = (n<>0) And (n<>1) And (n<>7)
    DigitToChange(4).Visible = (n<>1) And (n<>3) And (n<>4) And (n<>5) And (n<>7) And (n<>9)
    DigitToChange(5).Visible = True
    DigitToChange(6).Visible = (n<>1) And (n<>4) And (n<>7)
End Sub


I don't really know if this is helpful, but it amuse me for a little bit. wink2.gif

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 02:23PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month