How to use output status as input??

Lobobo

Member
Hi guys. I need some help with the code. I would like to use the output status (high or low) for my future programming as input. What command or function I should use for this. I can explain what I need verbally, not with the code as my program is very long. Basically my task is:

"If output 1 is high then goto subroutine"

how to write it right way to make it work?
Output 1 status is changed in very many places within the program, so I do not want next to each "output 1 = 1" additionally put temporary variable. I would like to use it some simple way as I expressed above. I feel this must be very simple, but cannot get it working.
Thanks for advice.
 

Milos

Member
It depends on your particular PICAXE chip. Generally - there is READOUTPUTS command in manual. You need to read output value in a variable and test it.
 

westaust55

Moderator
Which PICAXE chip are you using? :confused:

There is the READOUTPUTS commands as mentioned by Milos, but as the manual 2 states:
"This command is not normally used with M2, X1 or X2 parts as the outputs can be read directly with ‘let var = outpinsX’ ".

Output 1 status is changed in very many places within the program.
Could be wiorth your positing your program code as well.

Read Manual 2 around page 14 to 20 - leave it to you to select the right page as we do not know the specific PICAXE chip you are using.
 

Lobobo

Member
Thanks.

Thanks for your advice. I forgot to put chip ID. I'm using 18M2. Your suggestions helped me a lot. I wasn't able to make this myself, but now I am happy to carry on with my project. I wrote the following code as you adviced:
Code:
symbol PortB_status = b0                   'temp variable
let PortB_status = outpinsB                'temp var reads output status
if PortB_status = %00000010 then      'now it can be used in condition
do                                                 'whatever you want
endif
Thank you very much.

"Perfection in simplicity"
 

Milos

Member
Your code would work only if you do not use the other B pins as outputs. It would be better to write "if bit1 = 1 then ... " in your case.
Good luck with your project!
 

westaust55

Moderator
or try this:

Code:
symbol PortB_status = b0                   'temp variable
let PortB_status = outpinsB [COLOR="Red"]AND %00000010  [/COLOR]'temp var reads output status and mask unwanted bits
if PortB_status [COLOR="red"]> 0[/COLOR] then      ' is > 0 if the pin is high so now it can be used in condition
do                                                 'whatever you want
endif
 
Last edited:

Lobobo

Member
Your code would work only if you do not use the other B pins as outputs. It would be better to write "if bit1 = 1 then ... " in your case.
Good luck with your project![/QUOTE

Your guys advices are valuable, but the code above makes me think how in this case bit1 can be associated with portB as on my chip there's two output ports?

Otherwise I think my solution is as good because even if other outputs are used it wouldn't affect my if...then because...
:) And now while typing I realized you are right LOL
The masking idea is perfect.

Thanks.
 
Top