Kronos Robotics and Electronics
Site Map
 
Home Zeus Projects App Notes Downloads Dios Athena Forums
 

AAN155

Multiple Buttons on a Single IO Port

 

By Michael Simpson

 

Are you low on IO ports and want to add several buttons to you microcontroller project?   This approach works quite well.  By using the pot command we can add many buttons to a single IO port.

The pot command charges a capacitor then determines how long it takes to discharge.  By placing a resistor across the capacitor you can control the time it takes to discharge therefore the reading of the pot command. In this case we will use a .1uf capacitor and various resistors connected to buttons.

Athena Hookup

By using different values you can determine which button is being pressed. 

 

The Program (download it here)

'Multi Button

   dim button
   LOOKDOWNMODE=1

loop:
   gosub getbutton
   if button = 0 then
      goto loop
   endif

   print "button=",button
   goto loop



getbutton:
   pot 0,4,button
   lookdown button,button,5,10,22
   if button = 0 then
      return
   endif
   return
 

We used a lookdown command to convert the actual pot values to button numbers.  In this case the actual values were 5,10,22.   You will have to test for the resistors you use and change the lookdown command appropriately.  Place a print x command in front of the lookdown command to display the raw readings.

What about reading two switches at the same time?   With the right resistor combinations this can be done.  For example pushing button 1 and button 2 the raw reading is 4.  Pushing button 2 and button 3 the reading is 7.

Parts

Easy RS232 Driver  

Athena

Athena EDU

Breadboard Push Button

 

 

7.5V AC Adapter

9 Pin Cable

Breadboard and Wire Kit

Breadboard Regulator

 

Copyright © 2001 - 2007 Kronos Robotics