Further to my post http://matrixmultimedia.com/mmforums/vi ... php?t=2910 I now have a macro running to read my 4 menu setting switches on Port B upper nibble. It has
Interrupt on port B
Read port B upper nibble
Decode reading to decide which switch is pressed
Set one of 4 variables from 0 to 1 to indicate which switch is pressed.
Exit to main program.
Next problem is how long do I leave the variables set and how do I clear them back to zero? They have to remain set for about 1 second so that all the many subroutines of main code that need to react to these switches can react. Could pepper the main code with a β€clear variables to zero’ macro at critical points, but easy to forget where to put it so end up prematurely clearing them or forgetting to do so.
Better would be some sort of timer running in background that auto zeroed the 4 variables after 1 second. How can this be done? Would some variant of this code that you gave me in http://matrixmultimedia.com/mmforums/vi ... php?t=3425 work? Afraid I don’t understand timers yet.
Main Program
Start
Calculation - counter = 0
Interrupt - Enable timer interrupts
While 1 - Main Program Loop
End
Timer_Interrupt_Macro
Start
Decision - Counter = 255
YES: Decision - PIN on - YES - Turn Off Pin / NO - Turn On Pin
NO: Calculation - Counter = Counter + 1
End
Alternatively is there a much more elegent way to read and react to menu switch inputs?
Reading and reacting to menu switches
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Hello
if a timer is enabled with a timeout of 75hz then if you count 75 timeouts you have a second delay. This can then be used to clear the variables.
The timer hardware is fairly simple and there should be hundreds of example available for you to use.
if a timer is enabled with a timeout of 75hz then if you count 75 timeouts you have a second delay. This can then be used to clear the variables.
The timer hardware is fairly simple and there should be hundreds of example available for you to use.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel