Results 1 to 7 of 7

Thread: help!!!!!!!!!!!!!!!!!!1111

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2001
    Posts
    4

    help!!!!!!!!!!!!!!!!!!1111

    as i was saying i have 4 led like led1, led2,led3,led4
    and my program is a 4 bit counter which counts from 0000, 0001, 0010....to 1111. so what is the code to make the led light up whenever my string of numbers shows a 1. example
    when 0010 is being input, the 3rd led is being light up the rest are all off.
    to light the led the command is led3 = true
    thanks for helping guys/gals

  2. #2
    Fanatic Member InvisibleDuncan's Avatar
    Join Date
    May 2001
    Location
    Eating jam.
    Posts
    819
    Try:
    VB Code:
    1. Led1 = (Mid(CStr(Counter), 1, 1) = 1)
    2. Led2 = (Mid(CStr(Counter), 2, 1) = 1)
    3. Led3 = (Mid(CStr(Counter), 3, 1) = 1)
    4. Led4 = (Mid(CStr(Counter), 4, 1) = 1)
    Indecisiveness is the key to flexibility.

    www.mangojacks.com

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I'm trying, and I keep trying, but I cant come up with any code any more snug than that of InvisibleDuncan's
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    sqapg

    sample for u

    -= a peet post =-

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I prefer my binary converter
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    Thumbs up

    I do agree plenderj

    and thanks for that module... seems to contain some good common routines


    -= a peet post =-

  7. #7
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Perhaps a control array will trim it?
    VB Code:
    1. For i = 0 To 3
    2. Check1(i) = Mid(b, i + 1, 1)
    3. Next i

    To test it add 4 checkboxes in a control array and a command button, then add the code. Press the button to "count".

    VB Code:
    1. Option Explicit
    2. Dim c&
    3.  
    4. Private Sub Command1_Click()
    5.     Dim b$, i&
    6.    
    7.     If c > 15 Then c = 0
    8.     b = Format$(bin(c), "0000")
    9.    
    10.     For i = 0 To 3
    11.     Check1(i) = Mid(b, i + 1, 1)
    12.     Next i
    13.    
    14.     c = c + 1
    15. End Sub
    16.  
    17. Function bin(ByVal X As Long) As String
    18.     Do
    19.         bin = (X And 1) & bin
    20.         X = X \ 2
    21.     Loop While X
    22. End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width