Need suggestions for detecting the order multiple buttons are pressed

Hi guys,

I'm trying to make a 6 button PICAXE program that will detect the order that these 6 buttons are pressed in.
Specifically, I'd like to have 6 7-segment LED's indicate the order numerically. Ie 1,3,5,2,4,6 etc.

Timing is not really important. The buttons will not be pressed simultaneously. There will be a second or two between presses.

Any suggestions of where to start, tutorial wise or similar program would be appreciated.

Thanks

Doug
 

inglewoodpete

Senior Member
I use a fairly standard timer interrupt routine (T= 80 or 100mS) for all my keypad-scan routines (2 to 9 buttons). A valid keypress is recognised when a button is operated for 2 or more consecutive timer interrupts. However, no keypress is treated as valid (Ie available for use in the main routine) until all buttons are released. A counter can be used to flag long-held keys, allowing double the number of output states, if that makes sense.
 

Billo

Senior Member
It does not sound like you need n-key, of even multi-key rollover, but your application is not clear. Can you give a better idea as to what you are trying to accomplish?

If there is a 1 or 2 second laps between key presses, how is this enforced?

The reason I ask is that if 1 second is supposed to be the minimum, a routine specified for that will fail if the period falls to, let's say, .9 seconds.

How many key presses have to be remembered? What is this sequence used for?

Is it an analog keyboard, or a digital keyboard, or just a bunch of 6 key switches attached to 6 inputs of the PICAXE?

There are many ways to leave this cat 'ready to cook' (if you excuse the expression), but I think we need more information.

Do you have a schematic thought out? Maybe you could share that as a start.
 
Thanks for the responses.
The setup I envision is, indeed just 6 buttons that are connected to individual inputs on the PICAXE.

To try and describe it more clearly, all the switches will be NO (or NC) and the states will change sequentially. As the state changes,it will remain in the new state while the next switches are pressed. More correctly, the switches will be optical, each state changing as a result of a tab being pulled.

There will be no specific timing constraints in this application. The buttons will function, one at a time with the understanding that eventually, all 6 switches will ave changed state.

I hope this is clearer.
Thanks
Doug
 

rossko57

Senior Member
Poll the switches. Are you always starting from "all off"? Might that condition be used to indicate the start of the sequence?
You might use the scratchpad (@bptr), and as each switch goes active, record its identity there and increment the pointer. When the pointer/counter reaches six the job is done, and a sequence stored. A little extra code can detect if a previously active goes inactive, and if so, what you plan to do about that.
 

westaust55

Moderator
If each switch is on a separate input then you can use the SETINT command with the NOT parameter to monitor the six pins and store the corresponding port value, restore the interrupts and within the main program loop decode the port value to display the number of the switch pressed.

What if same switch is pressed twice?

If you are using an X1 or X2 PICAXE part then the NCD Unary math function can make short work to determine the switch/bit number.
If an X2 part the NOB math function makes short work to determine if more than 1 switch is pressed together.
 

hippy

Ex-Staff (retired)
Any suggestions of where to start
I would suggest splitting the project into three parts -

1) Reading the switches and determining which has been activated.

2) Displaying 6 data items on the 7-segment displays.

3) The code which takes the button activations and creates the data items to be displayed.

You can do those in any order but I'd choose the above. A circuit diagram of the hardware used would be needed to do the first two.
 
You guys are great!
The comment "...NOB math function makes short work..." Leaves me remembering that I'm a NOoB in all this ;)
Little by little, I'll get there.

Hardware-wise, I think I'll start with one PICAXE chip, with 12 (or more) I/O pins, 6 of which will be input (to NO/NC switches but ultimately, optical switches) and 6 output pins to LEDs. I think that will be a start, hardware-wise anyway. I'm sure it can be done with fewer pins, but this strikes me as simplest.

Thanks again,
Doug
 
Starting with "all on or all off". As long as we start from the same place....it doesn't matter.
Once the switches go back to the default state, the program should consider itself "reset".

Doug
 
Top