Skip to content

Commit 3c0da6a

Browse files
committed
examples/hwapi: button_led: Add GPIO pin read example.
Requires BUTTON defined in hwconfig, so far tested on DragonBoard 410c.
1 parent 1375c52 commit 3c0da6a

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

examples/hwapi/button_led.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import utime
2+
from hwconfig import LED, BUTTON
3+
4+
# Light LED when (and while) a BUTTON is pressed
5+
6+
while 1:
7+
LED.value(BUTTON.value())
8+
# Don't burn CPU
9+
utime.sleep_ms(10)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
from machine import Pin
22

33
# 96Boards/Qualcomm DragonBoard 410c
4+
#
45
# By default, on-board LEDs are controlled by kernel LED driver.
56
# To make corresponding pins be available as normal GPIO,
67
# corresponding driver needs to be unbound first (as root):
78
# echo -n "soc:leds" >/sys/class/leds/apq8016-sbc:green:user1/device/driver/unbind
89
# Note that application also either should be run as root, or
910
# /sys/class/gpio ownership needs to be changed.
11+
# Likewise, onboard buttons are controlled by gpio_keys driver.
12+
# To release corresponding GPIOs:
13+
# echo -n "gpio_keys" >/sys/class/input/input1/device/driver/unbind
1014

1115
# User LED 1 on gpio21
1216
LED = Pin(21, Pin.OUT)
17+
18+
# Button S3 on gpio107
19+
BUTTON = Pin(107, Pin.IN)

0 commit comments

Comments
 (0)