November 21, 2024, 09:18:35 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Scanning 15 inputs, trigger when all satisfied

Started by gadget-evilusions, September 14, 2015, 05:19:46 PM

Previous topic - Next topic

gadget-evilusions

I am looking for an elegant solution that isn't me typing 15 if-thens to scan thru pins 0-14 as inputs, and when all are satisfied, turn on out15 for 30 seconds. The tricky part is, I want to be able to change the combination of which of the 15 inputs need to be on, or off, to be considered satisfied and then turn on the out15.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

September 14, 2015, 10:02:54 PM #1 Last Edit: September 14, 2015, 11:31:04 PM by JonnyMac
When you learn how to use masking, this kinds of problems become fairly simple. Set your bit pattern into Triggers (IN14 is on the left, IN0 is to the right).

' =========================================================================
'
'   File...... bw_multi-trigger.bs2
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started... 14 SEP 2015
'   Updated... 14 SEP 2015
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

CtrlPort        PIN     15


' -----[ Constants ]-------------------------------------------------------

IsOn            CON     1                       ' for active-high in/out
IsOff           CON     0

Triggers        CON     %0111111111111111


' -----[ Variables ]-------------------------------------------------------

scan            VAR     Word
idx             VAR     Byte


' -----[ Initialization ]--------------------------------------------------

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %10000000 : DIRL = %00000000           ' only P15 is an output

  PAUSE 30000                                   ' inter-show delay


' -----[ Program Code ]----------------------------------------------------

Main:
  scan = $7FFF                                  ' scan 15 inputs
  FOR idx = 1 TO 25
    PAUSE 1
    scan = INS & scan
  NEXT

  IF (scan = Triggers) THEN
    CtrlPort = IsOn
    PAUSE 30000
    CtrlPort = IsOff
  endif

  GOTO Reset


' -----[ Subroutines ]-----------------------------------------------------


' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

So, if I wanted every other input to be on, and every other input to be off to be the "combination", then

Triggers        CON     %0111111111111111

becomes

Triggers        CON     %0101010101010101 ?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

September 14, 2015, 11:30:26 PM #3 Last Edit: September 14, 2015, 11:42:14 PM by JonnyMac
You got it.

Thinking about it, though, my original code could allow a set of inputs that you don't want. I have fixed it by presetting scan to $7FFF (all inputs) instead of the Triggers value. That way, if you have an input on a pin that should be clear, the code won't respond to it.
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components