Handler for Momentary Button
Moderators: adafruit_support_bill, adafruit
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
- samtkc
- Posts: 30
- Joined: Wed Oct 04, 2017 11:28 am
Handler for Momentary Button
Can someone provide example code for pushing a button value from a Momentary Button (IO Block) to a Pi Pico using CircuitPython? Basically, I want to set up a handler for the feed from a Momentary Button. I can do this in C using onMessage, but I don't know how to do this in CircuitPython.
- mikeysklar
- Posts: 13936
- Joined: Mon Aug 01, 2016 8:10 pm
Re: Handler for Momentary Button
This is from the Adafruit Pico guide CircuitPython section.
Code: Select all
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""
Button example for Pico. Prints button pressed state to serial console.
REQUIRED HARDWARE:
* Button switch on pin GP13.
"""
import time
import board
import digitalio
button = digitalio.DigitalInOut(board.GP13)
button.switch_to_input(pull=digitalio.Pull.DOWN)
while True:
print(button.value)
time.sleep(0.5)
- samtkc
- Posts: 30
- Joined: Wed Oct 04, 2017 11:28 am
Re: Handler for Momentary Button
Thanks for the example, though I guess I was not clear. I am looking for a way to push a value from the dashboard to the Pi Pico. The Momentary Button I referred to is a dashboard block. Also, I am fine with reading a value from the dashboard on the Pi Pico in CircuitPython. What I am looking for is a way to do this with a handler i.e. I do not want to be constantly checking the value of the dashboard Momentary Button. And similar to how this would be done in C using "onMessage".
- samtkc
- Posts: 30
- Joined: Wed Oct 04, 2017 11:28 am
Re: Handler for Momentary Button
Is this simply not possible???
- jwcooper
- Posts: 1004
- Joined: Tue May 01, 2012 9:08 pm
Re: Handler for Momentary Button
Here is a CircuitPython example that does an on_message for a feed sent from a dashboard. This example is using mqtt, which is the recommended approach for something like this:
https://github.com/adafruit/Adafruit_Ci ... ack.py#L79
https://github.com/adafruit/Adafruit_Ci ... ack.py#L79
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.