Two buttons muti functions
Hello,
···· I want to be able to have two buttons one up and one down and have it output to only four different outputs. Would this work?
Position···· Var·· byte
Main:
· If ButtonUp = 1 then
Position = Position max 4
Position = Position + 1
Elseif ButtonDown = 1 then
Position = Position min 1
Position = Position - 1
endif
If Position = 1 then
outputA = 1
elseif Position = 2 then
outputB = 1
elseif Position = 3 then
outputC = 1
elseif Position = 4 then
outputD = 1
endif
· GOTO Main
···· I want to be able to have two buttons one up and one down and have it output to only four different outputs. Would this work?
Position···· Var·· byte
Main:
· If ButtonUp = 1 then
Position = Position max 4
Position = Position + 1
Elseif ButtonDown = 1 then
Position = Position min 1
Position = Position - 1
endif
If Position = 1 then
outputA = 1
elseif Position = 2 then
outputB = 1
elseif Position = 3 then
outputC = 1
elseif Position = 4 then
outputD = 1
endif
· GOTO Main
Comments
If the outputs are sequencial on the same port you could just use the shift operator instead of having to set each on individually.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
“The United States is a nation of laws -· poorly written and randomly enforced.” - Frank Zappa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
www.hittconsulting.com
·
In this case the pos.2 = 0 does the same thing as pos = pos // 4 -- without the division.
JonnyMac That is a little less code and it should work I cant test it right now my SX blitz is not working after my Three year old assitant technician spilt her Cola on it..lol but the SX48 protoboard survived..
The first line clears your outputs; the second sets the correct bit of a temporary variable; the final line sets that bit on the port.
Your code steps the 1 of tmpB1 through the pos variable that way their would only be one output on at a time right?
I have an extra prototype board and I plan to solder a ribbon cable header to the SX48 proto board and then run the wires to the prototype board so I can hook up some leds to tes with.
Thanks again