using pin as an input and an output.
tedbeau
Posts: 48
Ok, I searched the forum post and the support area and cannot find an example. I know the documentation says it is possible to use the same stamp pin as both a input and an output.
My question is, in the Button command, what is the difference between downstate and targetstate. Which one decides when to perform an action. In the description below, I want to change which input causes the same action to occur. I also need to know if the output state of a pin effects the input.
····················· VDD
························ l
························ l
·······················LED
························ l········switch··
························ l_______/ _____/\/\/\/\_________PO
················································ 200 ohm
················································
Step 1.
Here is what I want, at startup of the program pin 0 is using a pull down resister to light an LED. There is also a slide switch in the circuit that is closed, between VDD and the LED. P0 is an output and I switch it from high, (LED off) Pause, switch it to low, (LED on) Pause, repeat. This is so I know the program is running and it gives me a delay to set the robot into position and back away.
Step 2
Main program runs.
When the program finishes I want to be able to rerun it by changing the switch position. Since the switch is closed, the input of P0 should be in a high state so I want to use the button command, with downstate(or is it targetstate) of 0.·I realize if I use a momentary button I could just watch to see PO go low when it is pressed, but I do not want to have to hold the button down while step 1 above is running to see if the LED flashes. So I slide the switch to open position, the downstate/targetstate of·pin P0 now reads low. When I see this I·change the button downstate/targetstate to High. (this will be explained in step 3). Then I go·back to the main run portion of the program in step 2 above.
Step 3.
Now when the program finishes the switch is still open and if I had left my button downstate/targetstate at low I and would automatically loop back to step 2. Since the d/tstate was changed I wait for the switch to be moved again. If I want to run the program again I slide the switch to closed, matching the d/tstate of high, reset d/tstate to low, return to main. and on and on and on......
·
My question is, in the Button command, what is the difference between downstate and targetstate. Which one decides when to perform an action. In the description below, I want to change which input causes the same action to occur. I also need to know if the output state of a pin effects the input.
····················· VDD
························ l
························ l
·······················LED
························ l········switch··
························ l_______/ _____/\/\/\/\_________PO
················································ 200 ohm
················································
Step 1.
Here is what I want, at startup of the program pin 0 is using a pull down resister to light an LED. There is also a slide switch in the circuit that is closed, between VDD and the LED. P0 is an output and I switch it from high, (LED off) Pause, switch it to low, (LED on) Pause, repeat. This is so I know the program is running and it gives me a delay to set the robot into position and back away.
Step 2
Main program runs.
When the program finishes I want to be able to rerun it by changing the switch position. Since the switch is closed, the input of P0 should be in a high state so I want to use the button command, with downstate(or is it targetstate) of 0.·I realize if I use a momentary button I could just watch to see PO go low when it is pressed, but I do not want to have to hold the button down while step 1 above is running to see if the LED flashes. So I slide the switch to open position, the downstate/targetstate of·pin P0 now reads low. When I see this I·change the button downstate/targetstate to High. (this will be explained in step 3). Then I go·back to the main run portion of the program in step 2 above.
Step 3.
Now when the program finishes the switch is still open and if I had left my button downstate/targetstate at low I and would automatically loop back to step 2. Since the d/tstate was changed I wait for the switch to be moved again. If I want to run the program again I slide the switch to closed, matching the d/tstate of high, reset d/tstate to low, return to main. and on and on and on......
·
Comments
If I have to, I can use a seperate Stamp pin to check the switch, but since the manual suggests that it's possible to use the pin as an input and an output I thought I would save a pin this way.
Ted
The way you are using the slide switch doesn't fit the way the BUTTON statement is intended to be used. When the switch is open, you have a floating input on the Stamp and it will react to electrical noise in the vicinity. You need a pulldown resistor, perhaps 100K to ground from the I/O pin.
In your program, you'd just test for the closed state of the switch with "INPUT 0" followed by "IF IN0 = 1 THEN GOTO closed". If the switch is closed, you can turn on the LED with "LOW 0" or turn it off with "HIGH 0" or "INPUT 0".
Thanks
Ted
Sometimes I just need to think about this stuff in the back of my head for a few days.
Thanks for all the help though. The forums like this one and the NSbasic for Palm forum are wonderful places where people give freely of their time and experience to help each other. I always try to add any suggestions to challenges that I have run across, of course I'm a newbie as far as Stamps go so it may be a while before I am to contribute here.
Ted