Act on "change of state" only.

Grant Fleming

Senior Member
I've written a programme that detects changes in input switches and latches the various outputs to go with this-this part works well for me. I am also displaying with sertxd command to a serial terminal when a switch is high or low but as I have a programme loop the sertxd keeps repeating (obviously). I am looking to using sertxd only with change of state occuring. Could I assign variables to these inputs, use lookup, lookdown, use interrupt somehow?? If someone could point me in the right direction to which command/commands to use I will try to work it out.
Thanks,
Grant
 

SD2100

New Member
This might do what you want ???, the variable <i>latch </i> toggles between 0 &amp; 1 as the state of pin 1 changes, this only allows one sertxd on change of pin1.

<code><pre><font size=2 face='Courier'>
symbol latch = b0
Start:
if pin1=0 and latch=0 then
sertxd(&quot;Pin 1 low&quot;,13,10)
latch=1
elseif pin1=1 and latch=1 then
sertxd(&quot;Pin 1 high&quot;,13,10)
latch=0
end if
goto start

</font></pre></code>
 

Grant Fleming

Senior Member
Phil &amp; Bloody-Orc-thanks for your replies. Phil-your piece of code looks interesting-I will now try to incorporate it into mine. Below I have posted the main body (the part we are concerned with)of my code for you to see what you think.
Cheers,
Grant
 

Grant Fleming

Senior Member
Here it is:'INPUT CHANNEL MONITOR WITH DATALOGGER
'GJ Fleming
'4 Nov 2006
'using 7 seg display driver 4026 (2 inputs)
'7 segment display runs through while scanning for high input on channels
'each channel LED lights while scanning through
'channel input will stay high if activated by latching relay (until manually released)
'when high input occurs, channel LED latches on (until hard reset)


init:
let pins=%00000000
let pinsc=%00000000

main:
let b0=0
let b1=1
let b2=2
let b3=3
let b4=4
let b5=5

scanning:
sertxd(&quot;SCANNING! &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;,cr,lf)

scan:
high 2 'turn on LED 1
if pin1 = 1 then show_1
gosub thump1 'display 1
low 2 'turn off LED 1

high 3 'turn on LED 2
if pin2 = 1 then show_2
gosub thmpadv 'display 2
low 3 'turn off LED 2

high 4 'turn on LED 3
if pin3 = 1 then show_3
gosub thmpadv 'display 3
low 4 'turn off LED 3

high 5 'turn on LED 4
if pin4 = 1 then show_4
gosub thmpadv 'display 4
low 5 'turn off LED 4

high 6 'turn on LED 5
if pin5 = 1 then show_5
gosub thmpadv 'display 5
low 6 'turn off LED 5
goto scan

display:

show_1:
gosub thump1
if pin1 = 0 then show_2
sertxd(&quot;Channel 1 activated&quot;,cr,lf)
high 2 'latch chan1 LED
pause 1000 'pause chan1 display

show_2:
gosub thmpadv
if pin2 = 0 then show_3
sertxd(&quot;Channel 2 activated&quot;,cr,lf)
high 3 'latch chan2 LED
pause 1000 'pause chan2 display

show_3:
gosub thmpadv
if pin3 = 0 then show_4
sertxd(&quot;Channel 3 activated&quot;,cr,lf)
high 4 'latch chan3 LED
pause 1000 'pause chan3 display

show_4:
gosub thmpadv
if pin4 = 0 then show_5
sertxd(&quot;Channel 4 activated&quot;,cr,lf)
high 5 'latch chan4 LED
pause 1000 'pause chan4 display

show_5:
gosub thmpadv
if pin5 = 0 then display
sertxd(&quot;Channel 5 activated&quot;,cr,lf)
high 6 'latch chan5 LED
pause 1000 'pause chan5 display
goto display


thmpadv: 'thump advance (pulse increment up one)
for b3 = 1 to b1
pulsout 1,10
next b3
return


thump1: 'reset display to zero &amp; pulse to show 1
pulsout 1,10
for b3 = 1 to b1
pulsout 0,10
next b3
return















 

Grant Fleming

Senior Member
Thanks Phil! Got my programme working nicely now with sertxd at &quot;change of state&quot; only. A nice bit of code of yours-I will certainly keep that trick in mind for later projects.
Cheers,
Grant
 

SD2100

New Member
Grant, sorry for no reply but have had major phone problems, fixed now. Good to see you have your program working.
 
Top