November 21, 2024, 11:24:18 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.


6 inputs, but differentiate which are connected correctly

Started by gadget-evilusions, May 25, 2016, 01:25:40 AM

Previous topic - Next topic

gadget-evilusions

I have an item that I build, that has 6 connections (numbered 1-12). When all 6 connections are connected correctly (1 to 3, 2 to 8, etc), it turns on a relay. The issue I have, is that since 5v+ on the header pins is common, as long as the connections connect any of the points that are 5v+ to an input pin, the item is seen as completed correctly. Is there a way, for me to differentiate whether P6.W is connected to P6.R, or P5.R for example. I am trying to make only one correct combination right, but I am always ending up with 6 that could be correct.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JackMan

The short answer to distinguish one R pin from another is no. I assume you have 12 buttons of which the correct combination of 6 will energize the relay. I think this can be done with the switch wiring and not reliant on the Prop-1. Wire the 6 correct switches in series so that each of the them has to be closed to complete the circuit back to the Prop-1 input. The other 6 switches can just be dummies. Not sure if this will work for your application but it's a thought.

JonnyMac

For the kind of puzzle you're fabricating you need twice as many connections. To do a check you make one pin an output then look at its corresponding input to see if it went high. If that's true you move on to the next, otherwise you go back to the beginning. With a Prop-1 you could test three connections this way.
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

Ok, so that means I could do it with a prop-2. Would you be willing to write a program that checks the six sets of pins, and then turns on out 0 for 60 seconds when all are complete?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

I used P15 for the control output -- it's my normal style. Since the Prop-2 has setup jumpers on P12 - P15, make sure they're out (using the ULN as a pull-down) or in the DN position.

This uses a table for the output/input pin pairs which makes modifications easy using the table and Segments constant (you can have up to 7 segments with the Prop-2.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Unlock          PIN     15


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

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

Yes             CON     1
No              CON     0

Segments        CON     6
Complete        CON     Segments * 2            ' 2 pins per segment


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

addr            VAR     Byte
outPin          VAR     Byte
inPin           VAR     Byte
mask            VAR     Word

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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %10000000 : DIRL = %00000000           ' preset Unlock to off

  addr = 0                                      ' reset table


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

Main:
  READ addr, outPin, inPin                      ' read a pin set
  INPUT inPin                                   ' setup sense pin
  HIGH outPin                                   ' activate test pin

  mask = 1 << inPin                             ' test mask for input pin
  IF ((INS & mask) = 0) THEN

    GOTO Reset                                  ' start over
  ELSE
    INPUT outPin                                ' clear test pin
    addr = addr + 2                             ' update sequence address
    IF (addr < Complete) THEN Main              ' wait for next
  ENDIF

  Unlock = Yes                                  ' code complete, unlock
  PAUSE 60000

  GOTO Reset


' -----[ User Data ]-------------------------------------------------------

' Place output/input pairs in table

Sequence        DATA     8, 0
                DATA     9, 1
                DATA    10, 2
                DATA    11, 3
                DATA    12, 4
                DATA    13, 5
Jon McPhalen
EFX-TEK Hollywood Office

Jeff Haas

Something about this doesn't work for me.  I made this test as simple as possible to try to understand it.

- Connect a jumper wire from P8.W to P0.W
- Add a couple of debug statements to the code to see how the variables change, here's where they go:

 
Main:
  READ addr, outPin, inPin                ' read a pin set
  INPUT inPin                                   ' setup sense pin
  HIGH outPin

  DEBUG ? inPin   
  DEBUG ? addr
  PAUSE 500

  IF (inPin = 0) THEN
    GOTO Reset                                  ' start over


I never see inPin = 1.  I tried assigning inPin using the PIN directive and it does work with HIGH outPin:

inPin          PIN     0
.
.
.
  IF (inPin = 0) THEN
    GOTO Reset                                  ' start over


etc.

From what I can tell, something about the IF statement doesn't seem to like the pin number being assigned by the READ command.


JonnyMac

Good catch, Jeff! I loaned my Prop-2 so I didn't do a test (my fault) with actual hardware.

In order to test any pin we have to use a mask -- that's been added to the program. See above.
Jon McPhalen
EFX-TEK Hollywood Office