So at any given moment you will not know which button was hit and will have to scan again.
But even so, a flag for each button pressed is needed to keep it from regarding it as new press.
Ioannis
So at any given moment you will not know which button was hit and will have to scan again.
But even so, a flag for each button pressed is needed to keep it from regarding it as new press.
Ioannis
Regarding flags, here is a trick I use:
This creates bit flags. To use them:Code:ButtonA VAR WORD Button1 VAR ButtonA.0 Button2 VAR ButtonA.1 ...... Button16 VAR ButtonA.15
Code:Button4 = PORTC.3
If you have many inputs scattered around various ports and you want to "gather them" in one consecutive block so you can iterate over them using a loop then sure, why not. Otherwise I must say I don't see the point of doing that. You might as well simply alias the bit variable directly to the port bit/pin and be done (after all, the Port registers is just another byte in memory - right).
You'll save RAM, FLASH and processor cycles by not first copying the value of one bit variable (PortC.3) to another (Button4) only to then evaluate the state of Button4 variable.Code:Button4 VAR PortC.3
But, I might be missing the point alltogether, in which case I apologise.
/Henrik,
Here there are not ports... Only a ADVAL from ADC since the buttons are read as analog voltage.
Ioannis
its a fairly simple process , 10 bits per button is easy , 8 bits with a bit of effort
providing the button check is called in a loop at a relatively consistent rate.
the program structure matters , spaghetti code won't get good results
sudo method
Code:b1cnt var byte newb1 var bit b1dun var bit b2cnt var byte newb2 var bit b2dun var bit osc=8 t1con=$01;32mS main if pir1.0 pir1.0=0 gosub getkey if newb1 gosub dob1 if newb2 gosub dob2 endif goto main getkey: read adc b1cnt = b1cnt<<1 b2cnt = b2cnt<<1 if adc in b1 range b1cnt = b1cnt+1 elseif if adc in b2 range b2cnt = b2cnt+1 endif if !b1dun if b1cnt=255 then newb1=1 ;32*8mS else if b1cnt=0 then b1dun=0 endif if !b2dun if b2cnt=255 then newb2=1 else if b2cnt=0 then b2dun=0 endif return dob1: b1dun=1 newb1=0 do b1 stuff return dob2: b2dun=1 newb1=0 do b2 stuff return
Warning I'm not a teacher
Bookmarks