I am not checking every pin; I am using the button command so I can de-bounce the switches.
I am not checking every pin; I am using the button command so I can de-bounce the switches.
Ok button command is overrated and too complicated.
i am not home and do not have the manual with me so bear with me if I error.
some of the syntax may be incorrect above but it should steer you to what you are wantingCode:myVar var byte[5] myVar.0 = portB.0 myVar.1 = portB.1 myvar.2 = portB.2 myvar.3 = portB.3 myvar.4 = portB.4 check: if myVar != 0 then pause 50 if myVar != 0 then select case myvar case 0 goto check case1 ' button1 pushed do something . . . fish case2 ' button2 pushed do something . . .cut bait case3 ' 2 buttons pushed do another something . . . look for better lake case 4 ' button3 pushed . . . case 7 ' 3 buttons pushed do or not do you decide case else goto check end select endif else goto check
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
Thank you for your help, so, you think is over rated, I see you are de-bouncing by pausing, but this will cause the software to repeat the press if someone holds the button pressed, the button command takes care of all this.
Another idea.. sort of.
I do not think it is likely that two buttons will be pressed at the same time. So if the buttons are on the same port then read the port twice to see if the second one has been pushed.
Untested but something like
Code:CHECK_BUTS: BUTVAR = PORTB & $1F IF BUTVAR >= 1 THEN CHECK2 GOTO CHECK_BUTS CHECK2 PAUSE 50 BUTVAR = PORTB & $1F SELECT CASE BUTVAR 'insert case statements GOTO CHECK_BUTS
Dave
Always wear safety glasses while programming.
Hi,
BUTTON Command could be fine here ... let's suppose button tie pin to ground.
As the debouncing do not occur if button is not pressed ( Mr de la Pallice )... scanning is very fast !Code:SCAN: FOR I = 0 to 4 BVar = 0 BUTTON PORTB.0[I],0,255,0,BVar,1,Action NEXT I I = 255 ' just to allow CASE 0 ... Action : SELECT CASE I CASE 0 ... ... CASE ELSE GOTO SCAN END SELECT
CQFD
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
For twin Button press ...
just add another scan loop ...
with 16 bits for RESULT, RESULT.Highbyte for I, RESULT.Lowbyte for J, .... you can even check in which order the buttons have been pushed ...Code:SCAN: RESULT = 0 FOR I = 0 to 4 BVar = 0 BUTTON PORTB.0[I],0,255,0,BVar,1,Action NEXT I GOTO SCAN ' No need to go further ... Action : RESULT.I = 1 ' Store the first button pushed PAUSE 250 ' Let a little time for pushing the ' next button ... FOR J= 0 to 4 IF J = I THEN I = I+1 ' Button already pushed !!! ... Skip test. BVar = 0 BUTTON PORTB.0[I],0,255,0,BVar,1,Action2 NEXT J GOTO Action1 ' Only one button Pushed ... Action2: RESULT.J = 1 ' Store the second button pushed Action1: SELECT CASE RESULT CASE %00000001 ' Button 0 alone ... CASE %00000010 ' Button 1 Alone ... CASE %00000100 ' Button 2 Alone ... ... ... CASE %00000011 ' Buttons 0 and 1 ... or 1 and 0 ... CASE %00000101 ' Buttons 0 and 2 ... or 2 and 0 ... ... ... CASE %00000110 ' Buttons 1 and 2 ... or 2 and 1 ... CASE %00001010 ' Buttons 1 and 3 ... or 3 and 1 ... ... ... CASE %00001100 ' Buttons 2 and 3 ... or 3 and 2 ... CASE %00010100 ' Buttons 2 and 4 ... or 4 and 2 CASE ELSE GOTO SCAN END SELECT
Too much ??? Ok, I take it back to my kangaroo pocket ...
Alain
Last edited by Acetronics2; - 30th August 2009 at 13:38.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
I want to thank everybody for their great help. I think I have enough to get me going here...
Arrrgh !!!
a little typing bug :
should have beenCode:IF J = I THEN I = I+1 ' Button already pushed !!! ... Skip
as everybody did notice ...Code:IF J = I THEN J = J+1 ' Button already pushed !!! ... Skip
Alain
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Bookmarks