Shop OBEX P1 Docs P2 Docs Learn Events
bs2 7 segment led counter — Parallax Forums

bs2 7 segment led counter

bs2-manbs2-man Posts: 23
edited 2010-04-26 23:08 in BASIC Stamp
lol.gif·roll.gif·lol.gif·lol, want to use 1 maybe 2 7 segment led's 2 count wen i press a button. i dont know where 2 start but i really need help with da programming. not so much the schematic. oh and please comment 4 me. i'd really, really, really, appreciate it! confused.gifcool.giffreaked.giflol.gifeyes.gif

Post Edited (bs2-man) : 2/17/2010 12:58:43 AM GMT

Comments

  • FranklinFranklin Posts: 4,747
    edited 2010-02-17 00:03
    There is a thread on this here some where if Parallax ever fixes the search function you can search for it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • bs2-manbs2-man Posts: 23
    edited 2010-02-17 00:19
    i cant find it.
  • bs2-manbs2-man Posts: 23
    edited 2010-02-17 00:41
    wat should i do?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-02-17 00:56
    You will probably find some useful information in the Nuts and Volts Columns that you can reach from the main Parallax webpage by clicking on the Resources tab.

    For learning how to program, start with the "What's a Microcontroller?" tutorial and the "BASIC Stamp Syntax and Reference Manual". Both are through the Downloads & Press link. The Manual is under BASIC Stamp Documentation and the tutorials are under Stamps in Class Downloads.
  • bs2-manbs2-man Posts: 23
    edited 2010-02-17 00:58
    ill start looking around and if i find it, ill let u know. thanks!
  • bs2-manbs2-man Posts: 23
    edited 2010-02-17 01:10
    ok, i just realized somthing, one of the displays is common anode and the other is common cathode.
  • stickystampstickystamp Posts: 16
    edited 2010-02-17 17:44
    bs2-man I started a thread on this a couple weeks ago here is a link let me know if I can help I got the first 7 segment to count but I 'm having a little difficulty multiplexing to the 2nd 3rd and 4th.

    http://forums.parallax.com/forums/default.aspx?f=5&m=424384

    Stickystamp
  • bs2-manbs2-man Posts: 23
    edited 2010-02-17 22:24
    ok, what is the code 4 one 7 segment display?
  • bs2-manbs2-man Posts: 23
    edited 2010-02-17 22:24
    ok, what is the code 4 one 7 segment display?
  • Spiral_72Spiral_72 Posts: 791
    edited 2010-02-18 13:48
    bs2-man said...
    ok, what is the code 4 one 7 segment display?


    Sorry about the formatting. I copy-pasted it.



    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    Digit0 DATA %11101111
    Digit1 DATA %10001100
    Digit2 DATA %11010011
    Digit3 DATA %11010110
    Digit4 DATA %10110100
    Digit5 DATA %01110110
    Digit6 DATA %01110111
    Digit7 DATA %11000100
    Digit8 DATA %11110111
    Digit9 DATA %11110110


    DATaddr VAR Word ' Word variable for our pointer
    counter VAR byte ' Keep track of current digit
    Dchar VAR byte ' Variable to keep digit in
    INPUT 3 ' Make pin 3 an input for the button
    DIRH = %11111111 ' Make pins 8-15 outputs for the display

    '
    [noparse][[/noparse] Program Code ]

    counter=0 ' initialize counter
    DATaddr = Digit0 ' Make pointer = start of data table


    Main: ' Main program loop

    READ DATaddr + counter, Dchar ' Read the character (byte size by default) from our marker (Digit0) + counter
    OUTH = Dchar ' Send the value to port
    DEBUG DEC Dchar ' Send value to console

    waitkey:
    IF IN3=0 THEN waitkey ' Has the button been pressed? No? try it again
    PAUSE 250 ' For a little button debounce, wait 250ms

    counter = counter + 1 ' increment counter
    if counter > 9 then counter = 0 ' limit the counter and roll it back over to zero

    goto main

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "puff"...... Smile, there went another one.
  • JDJD Posts: 570
    edited 2010-02-19 19:16
    bs2-man,

    There·are·detailed examples of controlling a 7-segment display with the BS2 in What's A Microcontroller? text·we offer. It is in chapter 6 "Digital Display" and it covers the programming and explanations very well; the book can be downloaded for free so it can be used for a quick reference. Here is a link for your review and reference.

    What's A Microcontroller?:
    http://www.parallax.com/Portals/0/Downloads/docs/books/edu/Wamv2_2.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • legoman132legoman132 Posts: 87
    edited 2010-02-20 02:13
    If you wanted to do a little more work on the hardware side to make the software side a little easier, you could use a BCD to seven-segment decoder (I have used the 4511 with a manual input, but it only works with common cathode displays). this would also require fewer I/O pins (four for BCD input). You output the required digit in binary form (Write to OUTA, OUTB, OUTC, or OUTD, use the DIG command and store value in a Nibble). OUTA is the first four I/O pins, OUTB for the second set, and so on.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    'displays the first digit of a two-digit number with a seven segment decoder
    'decoder conneced to I/O pins 0-3
    
    dispnum VAR Byte 'number to be displayed
    digit VAR Nib 'variable to hold first digit
    DIRA = %1111 'sets pins 0-3 to outputs
    
    DEBUG "enter number: " 'get a number
    DEBUGIN DEC2 dispnum
    DEBUG CR
    
    digit = dispnum DIG 1 'get first digit
    OUTA = digit ' send digit to decoder (I belive that pin 0 is connected to the LSB pin
    'on the decoder)
    
    
  • legoman132legoman132 Posts: 87
    edited 2010-02-20 02:22
    Note: the decoder could allow you to use four displays
  • bs2-manbs2-man Posts: 23
    edited 2010-02-22 13:05
    ok, ill try that.
  • fallenfallen Posts: 1
    edited 2010-04-26 16:36
    I need the 7 segment display to act as an UP/DOWN counter with 2 push pins. What do I need to add to the code pasted above to add an additional push pin & cause the 7 segment to count down or subtract from the pin1 up code?
  • metron9metron9 Posts: 1,100
    edited 2010-04-26 23:08
    fallen said...
    I need the 7 segment display to act as an UP/DOWN counter with 2 push pins. What do I need to add to the code pasted above to add an additional push pin & cause the 7 segment to count down or subtract from the pin1 up code?
    Well, what I would suggest you do is try and understand the code that makes it count up. Once you do that you can move on to trying your own code to make it count down.

    What I mean is, it is a very simple thing to do if you understand the up counting. I assume you do not understand the code and you should ask questions about the existing code that you do not understand. Then you will be using much more of your own brain cells to come up with a solution.· You need to try your own code, if it dosen't work then ask questions after you toy with it for an hour or so.

    Typically, the good programmers here and on other forums have spent thousands of hours testing code while making thousands of mistakes. When I started coding commodore 64 computers I was coding for at least 12 hours a day perhaps 18 and pulling all nighters debugging those programs. That is how i learned and i will bet most here remember those days with a feeling of satisfaction when they whip up a complicated project and understand it will typically involve many hours of head banging, debugging the logic that somehow gets twisted even now.

    Just get in there and make some changes, if going up uses addition, what do you think would make the counter go down?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
Sign In or Register to comment.