push buttons

Everything todo with programming goes HERE.
Post Reply
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

push buttons

Post by iceman »

well this is hardware but does require software so ive posted it in programming

if like me your into electronics and use micro controllers you will know that they have a very limited number of port lines

sometimes a project requires just 1 or 2 more lines than the chip has and you end up buying the next device up to gain just a few lines (not cost effective)

if your project uses a few push buttons inputs its possible to save input lines buy putting all switches on just 1 i/o pin saving a lot of port lines ! :o

4 buttons shown but you can add as many as required
Image

the software to read these switches is very simple and based on a counter

Code: Select all

set port pin for output and output a logic 0 to discharge capacitor
zero counter
set port pin for input

repeat
counter++
until (port input = 1) or (counter = max timeout)
choosing small capacitor & resistor values will add little time overhead to the overall program

hope you found this helpfull

btw if you remove the resistors and switches and replace with a variable resistor you have a way of measuring analogue control position
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
User avatar
Z-Man
God & Project Admin
Posts: 11587
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Post by Z-Man »

Heh. I remember this is the way the classic analog PC joystick works. Only that the time overhad IS pretty significant there. I remember hacking the Linux joystick driver so UAE could run at full speed :)
User avatar
iceman
Reverse Adjust Outside Corner Grinder
Posts: 2448
Joined: Fri Jan 09, 2004 9:54 am
Location: Yorkshire, England. Quote: Its the fumes, they make one want to play
Contact:

Post by iceman »

heh yeah bad choice of values can end up with a long sampling time

keep em small and you can get your sampling time down to a few microseconds

or do the timer counter thing on an periodic interupt to have minimum impact on the main program
Image He who laughs last, probably has a back-up
Image
Image
sorry about the large animated gif
Post Reply