Skip to Content
Raspberry Pi 3 Cookbook for Python Programmers - Third Edition
book

Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

by Steven Lawrence Fernandes, Tim Cox
April 2018
Beginner content levelBeginner
552 pages
13h 58m
English
Packt Publishing
Content preview from Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

How to do it...

Create a gpiokeys.py script as follows:

#!/usr/bin/python3 #gpiokeys.py import time import RPi.GPIO as GPIO import uinput #HARDWARE SETUP # GPIO # 2[==G=====<=V==]26[=======]40 # 1[===2=1>^=====]25[=======]39 B_DOWN = 22 #V B_LEFT = 18 #< B_UP = 15 #^ B_RIGHT = 13 #> B_1 = 11 #1 B_2 = 7 #2 DEBUG=True BTN = [B_UP,B_DOWN,B_LEFT,B_RIGHT,B_1,B_2] MSG = ["UP","DOWN","LEFT","RIGHT","1","2"] #Setup the DPad module pins and pull-ups def dpad_setup(): #Set up the wiring GPIO.setmode(GPIO.BOARD) # Setup BTN Ports as INPUTS for val in BTN: # set up GPIO input with pull-up control #(pull_up_down can be: # PUD_OFF, PUD_UP or PUD_DOWN, default PUD_OFF) GPIO.setup(val, GPIO.IN, pull_up_down=GPIO.PUD_UP) def main(): #Setup uinput events = ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Raspberry Pi for Python Programmers Cookbook - Second Edition

Raspberry Pi for Python Programmers Cookbook - Second Edition

Tim Cox

Publisher Resources

ISBN: 9781788629874Supplemental Content