bs2 7 segment led counter
bs2-man
Posts: 23
···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!
Post Edited (bs2-man) : 2/17/2010 12:58:43 AM GMT
Post Edited (bs2-man) : 2/17/2010 12:58:43 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
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.
http://forums.parallax.com/forums/default.aspx?f=5&m=424384
Stickystamp
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.
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
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!