Response to pin inputs

I have frequently read pin values using ADC and then created outputs depending on the resulting values.
Is there a more direct way such as in effect being able to say 'If pinC.0 = 1 and if PinC.1 = 1 and pinC.2 = 0 then goto...'? or similar combinations of multiple pin inputs?

I'm worried that I am getting too old for this and have forgotten something I used to know...

Thanks...
 

Aries

New Member
Yes - what you are doing is perfectly all right. pinX.n is the logical (0,1) value of the pin named X.n and can be used like any other variable in a test.
PS - you don't need the goto after the then.
 
Thank you Aries.
It's been quite a while since I last did this and it seems the brain is getting a bit rusty!
I had too many 'if's ie: 'If pinC.0 = 1 and if PinC.1 = 1 and if pinC.2 = 0 then...'
The 'goto' is to then get to different routines depending on the above test of inputs.
Now it works as I wanted.
Thanks again
 

oracacle

Senior Member
you could read the entire port at once and compare it to what you want
Code:
main:
    let b0 = pinsc
    if pinsc = %00000110 then
        'do stuff here
        'or you could use a goto
        sertxd ("Hello World",13,10)
    end if
    pause 1000        'this is here to make the simulation easier to read
    goto main
The code inside the "if" statement will only execute if pins c.1 and c.2 are high.

in some situation you may need to mask bits, such as not need read the entire port due to using some as an ouput.[/code]
 
Thank you for that suggestion Oracle. I will record that information for future use.
For the present project, (stopping a incoming water supply and sounding an alarm in the event of either of two pumps failing but with some easily adjustable parameters) the code as discussed above is perfectly suited.
 

Aries

New Member
The 'goto' is to then get to different routines depending on the above test of inputs.
My point was that the statement
Code:
if pinC.1 = 1 and pinC.2 = 0 then XYZ
does exactly the same as
Code:
if pinC.1 = 1 and pinC.2 = 0 then goto XYZ
 
Last edited:

Flenser

Senior Member
John, because you are using this code to trigger an alarm I want to clarify oracacle's comment "The code inside the "if" statement will only execute if pins c.1 and c.2 are high" in post #4.

The code in post #4 will trigger the alarm when the only pins which are high in portC are c.1 and c.2. If any one of the other pins, are also high then the alarm will _not_ trigger. e.g. if pins c.0, c.1 & c.2 are high then the alarm code will not be run.

The original IF statement you used "If pinC.0 = 1 and if PinC.1 = 1 then" will trigger the alarm pins c.0 & c.1 are high no matter whether the other pins are 0 or 1.

If you would still like to use the style of test from oracacle's post #4 then this modification will trigger the alarm when portC pins c.1 & c.2 are high no matter whether the other portC pins are 0 or 1:
Code:
let b0 = pinsc & %00000110        ; filter out the values for just the pins we are interested in
if b0 = %00000110 then            ; then test to see if all the pins we are interestd in are "1"
 

hippy

Ex-Staff (retired)
Is there a more direct way such as in effect being able to say 'If pinC.0 = 1 and if PinC.1 = 1 and pinC.2 = 0 then goto...'?
One technique is this -
Code:
b0 = 0
bit0 = pinC.0
bit1 = pinC.1
bit2 = pinC.2
That will then put a 0 to 7 value in 'b0' which can be handled with SELECT-CASE, IF-THEN, ON-GOTO or ON-GOSUB.

The above is the same as 'b0 = pinsC & %00000111' but allows non-sequential pins to be used, pins to be swapped around if that turns out to be convenient.

In your case, if you are wanting to detect the suggested condition, do the above, then "If b0 == %110 Then ...'. or 'If b0 = 6 Then ...'.
 
(apologies for not replying sooner - I tried to change my email address and managed to lock myself out of the site...)

Thanks to you both for the further suggestions which I do appreciate for my further understanding.

The following is the basis of what I have used and which with some testing achieves exactly what I wanted.
Pins1, 2 and 3 are from pressure switches these being normally high (so that a signal failure will lead to the alarm condition).
If any one or more than one go simultaneously low, the Alarm routine stops the incoming water supply, sounds an audible alarm and illuminates one of 3 leds to indicate the pin that has gone low and therefore which drain requires attention.
The pause 500 is just to confirm the need for the alarm response.

Code:
Settime:

if pinC.1 = 1 and pinC.2 = 1 and pinC.3 = 1 then goto FLOW:

if pinC.1 = 0 or pinC.2 = 0 or pinC.3 = 0 then pause 500

endif
   
if pinC.1 = 0 or pinC.2 = 0 or pinC.3 = 0 then goto Alarm:
 
Top