Shop OBEX P1 Docs P2 Docs Learn Events
Push button function for P2 — Parallax Forums

Push button function for P2

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

  • RaymanRayman Posts: 14,768

    Yes, that should work...
    Set up the smartpin and then DRVH the pin.
    read the pin to detect switch state

  • JonnyMacJonnyMac Posts: 9,161
    edited 2021-12-12 03:41

    Here's how to do it in Spin:

    pub enable_pullup(pin)
    
      pinclear(pin)                                                 ' clear smart settings
      wrpin(pin, P_HIGH_15K)                                        ' set to pull-up mode
      pinhigh(pin)                                                  ' activate pull-up 
    

    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).

  • PropGuy2PropGuy2 Posts: 360
    edited 2021-12-15 16:49

    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

Sign In or Register to comment.