Push button function for P2
PropGuy2
Posts: 360
in Propeller 2
I have a simple SPST push button, one side connected to ground, the other connected to a Smart pin. I want to detect if it is open or closed.
Right now I am using an external 10K resistor tied to 3v3 volts and using a read pin function. It works OK
But with the Smart pin I am thinking, why not use the 15K Pullup function. So far no joy. Is this even possible? Any ideas?
Comments
Yes, that should work...
Set up the smartpin and then DRVH the pin.
read the pin to detect switch state
Here's how to do it in Spin:
You would read the pin in the same manner as you're doing with the external pullup.
Technically, the pull-ups aren't part of the "smart" modes; they're simple pin configurations (which may or may no be used with smart modes).
Here is a little Push Button code example I wrote up to test a SPST switch.
It uses the latest P2 Rev 2.6.0 Tool and ER Smith's VGA driver with the P1 font. Load all of the the included files in your sub-directory of choice.
Run the "P2 Push Button Code Example.spin" application.
The SPST switch connects to a Smart pin of our choice (i used pin 45) and Ground. A 75uH fixed inductor is optionally included to protect the P2 pin.
The program uses VGA group PinBase 48, but others of your choice will work. Likewise I used pin #45 as the switch's input pin, but any of the P2 pins will work.
Update - Listed some new P2 files for this Push Button Demo, and everything should work...
Cheers