examples/hwapi: button_led: Add GPIO pin read example.
Requires BUTTON defined in hwconfig, so far tested on DragonBoard 410c.
This commit is contained in:
parent
1375c52772
commit
3c0da6a359
9
examples/hwapi/button_led.py
Normal file
9
examples/hwapi/button_led.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import utime
|
||||||
|
from hwconfig import LED, BUTTON
|
||||||
|
|
||||||
|
# Light LED when (and while) a BUTTON is pressed
|
||||||
|
|
||||||
|
while 1:
|
||||||
|
LED.value(BUTTON.value())
|
||||||
|
# Don't burn CPU
|
||||||
|
utime.sleep_ms(10)
|
@ -1,12 +1,19 @@
|
|||||||
from machine import Pin
|
from machine import Pin
|
||||||
|
|
||||||
# 96Boards/Qualcomm DragonBoard 410c
|
# 96Boards/Qualcomm DragonBoard 410c
|
||||||
|
#
|
||||||
# By default, on-board LEDs are controlled by kernel LED driver.
|
# By default, on-board LEDs are controlled by kernel LED driver.
|
||||||
# To make corresponding pins be available as normal GPIO,
|
# To make corresponding pins be available as normal GPIO,
|
||||||
# corresponding driver needs to be unbound first (as root):
|
# corresponding driver needs to be unbound first (as root):
|
||||||
# echo -n "soc:leds" >/sys/class/leds/apq8016-sbc:green:user1/device/driver/unbind
|
# echo -n "soc:leds" >/sys/class/leds/apq8016-sbc:green:user1/device/driver/unbind
|
||||||
# Note that application also either should be run as root, or
|
# Note that application also either should be run as root, or
|
||||||
# /sys/class/gpio ownership needs to be changed.
|
# /sys/class/gpio ownership needs to be changed.
|
||||||
|
# Likewise, onboard buttons are controlled by gpio_keys driver.
|
||||||
|
# To release corresponding GPIOs:
|
||||||
|
# echo -n "gpio_keys" >/sys/class/input/input1/device/driver/unbind
|
||||||
|
|
||||||
# User LED 1 on gpio21
|
# User LED 1 on gpio21
|
||||||
LED = Pin(21, Pin.OUT)
|
LED = Pin(21, Pin.OUT)
|
||||||
|
|
||||||
|
# Button S3 on gpio107
|
||||||
|
BUTTON = Pin(107, Pin.IN)
|
||||||
|
Loading…
Reference in New Issue
Block a user