Hello, Can someone please help

MiB1986

Member
Hello,

I am looking at being able to write a program which can turn on and off an output from one switch, the switch has to be push button only, not latching.

So press 1 = ON and press 2 = OFF then press 3 = ON etc...

The program i want to use is:

b1 = 0

checkforsignal:
if pin1 = 1 then
b1 = b1 + 1
goto process
end if
pause 250
goto checkforsignal

process:
if b1 = 1 then
high 4
b1 = 0
goto checkforsignal
end if
if b1 <> 1 then
low 4
b1 = 0
goto checkforsignal
end if

but all what seems to happen is it, turns the output on and off very fast :(

please say where i am going wrong.

Thanks

 

Edited by - MiB1986 on 14/08/2007 15:04:01
 

boriz

Senior Member
You say “not latching”, then you describe a latching output “press 1 = ON and press 2 = OFF then press 3 = ON etc...”

Look up the TOGGLE command in the docs. Something like this should work:

<code><pre><font size=2 face='Courier'>
do
if pin1=1 then
toggle 4
do
loop until pin1=0
endif
loop
</font></pre></code>

Or..

<code><pre><font size=2 face='Courier'>
do
do
loop until pin1=1
toggle 4
do
loop until pin1=0
loop
</font></pre></code>

Or..

<code><pre><font size=2 face='Courier'>
b0=1
do
do
loop until pin1=b0
if b0=1 then
toggle 4
b0=0
else
b0=1
endif
loop
</font></pre></code>
 

MiB1986

Member
hi,

the switch im using is a momentary switch, and i want to have a latching output using the picaxe on output 4

i never considered the toggle idea, im sure i can throw a program together from the information given

Thankyou so much so far
 

leftyretro

New Member
The toggle function should work well for processing the output, however you should research and consider using the button function (or something similar) for 'reading' the input switch as switch contact bounce is sure to make your output operate erratic.

Good luck
Lefty
 
Top