Picaxe reading pins

Hello everyone,

Recently I´ve been trying to make an alarm using some buzzers and a magnetic switch (reed switch).

I´ve made the picaxe read the pins and so when pin0 = 1 the buzzer turns on.

Now my question is what code can I use to make the Picaxe read another Pin, and when that one is = 1 stop the buzzer?

If you post your code, we

If you post your code, we might be able to help you.

Have you read the PICAXE manuals?

code

main:
if pin0 = 1 then ledon

if pin0 = 0 then ledoff

ledon:

high 2

if pin1 = 1 then ledoff   i tried this but just turns it off momentarily


ledoff:

low 2

pause 100

goto main

Answer found no worries

main:
if pin0 = 1 then ledon

if pin0 = 0 then ledoff


ledon:
high 2

if pin1 = 1 then ledoff    Teh answer lies in this 2 lines
if pin1 = 0 then ledon

ledoff:
low 2

low 1

pause 100

goto main

 

Any ways thanks for worrying :smiley:

The commands are done in order

This is not a programming issues, this is a “draw a flow chart on paper” issue…

I would “remember” the state of things using a variable. --This is assuming you want a momentary push to equal a constant buzz.

 


main:
if pin1=1 then let b0=1
pause 100  'debounce the switch
endif

if pin2=1 then let b0=0
pause 100  'debounce the switch
endif

if b0=1 then high 3
else
low 3
endif

goto main

Another way of doing this

Another way of doing this might be like this;

main:
          if pin1 = 1 then gosub LEDon
          if pin2 = 1 then gosub LEDoff
          goto main
 
LEDon:
          high 3
          return
 
LEDoff:
          low 3
          return

It doesn’t involve use of memory if you don’t need to know the state later in your program. And you don’t need the debounce delay as the sub will only execute on button press and if it does it several times it doesn’t matter.

**I see **

I think I understand what you mean, I didnt think I had to debounce the switches s I was unsure about that, anyways I got it working thanks for the advices!

Switch debouncing is a

Switch debouncing is a problem that occurs with mechanical switching. The signal bounces on an off for a period and might mess up your program. You can read more about it here http://www.labbookpages.co.uk/electronics/debounce.html

Multiple pins

thank you for all the answers, but if I want to read multiple pins like this:

if pin1, pin2, pin3, pin4 = 1 then ledon

if I want to do something like that how can I write it, because commas will give syntax error just as using “and”

I do not know picaxe so im

I do not know picaxe so im just winging this. Would it be:

if pin1=1 and if pin2=1 and if pin3=1 and if pin4=1 then ledon

If that doesnt do it then maybe this:

if pin1=1 and pin2=1 and pin3=1 and pin4=1 then ledon

Like i said i do not know that this is right.

**OMG dude **

OMG i cannot believe this you actually solved ma problem!

YAY! thanks!

I believe if you do

I believe if you do something like:

let b0 = pinsC

you can look at the binary form of the value in b0 to see bitwise which pins are high or low. This will only work with the better PICAXEs (X2s, M2s).