Hardware Reference
In-Depth Information
FIGURE 8-14 Downloading and extracting python-uinput
3. Next, edit the marshmallow script to use the uinput Python library to map
the input of the marshmallow to a key on the keyboard. You can open marsh-
mallow.py in IDLE3 or type the following command in the LXTerminal win-
dow to open the ile:
cd Documents
nano marshmallow.py
Amend the Python code to include the new lines (shown in bold):
import RPi.GPIO as GPIO
import time
import uinput
GPIO.setmode(GPIO.BCM)
GPIO.setup(2, GPIO.IN)
device = uinput.Device([uinput.KEY_A])
while True:
if GPIO.input(2) == False:
device.emit_click(uinput.KEY_A)
print(“marshmallow makes a good input”)
time.sleep(0.5)
Here the keyboard key a has been used for the marshmallow button. You could
use any letter of the alphabet.
Search WWH ::




Custom Search