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...

  1. Create the shtdwn.py script as follows:
#!/usr/bin/python3 #shtdwn.py import time import RPi.GPIO as GPIO import os # Shutdown Script DEBUG=True #Simulate Only SNDON=True #HARDWARE SETUP # GPIO # 2[==X==L=======]26[=======]40 # 1[===1=========]25[=======]39 #BTN CONFIG - Set GPIO Ports GPIO_MODE=GPIO.BOARD SHTDWN_BTN = 7 #1 LED = 12 #L def gpio_setup(): #Setup the wiring GPIO.setmode(GPIO_MODE) #Setup Ports GPIO.setup(SHTDWN_BTN,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(LED,GPIO.OUT) def doShutdown(): if(DEBUG):print("Press detected") time.sleep(3) if GPIO.input(SHTDWN_BTN): if(DEBUG):print("Ignore the shutdown (<3sec)") else: if(DEBUG):print ("Would shutdown the RPi Now") GPIO.output(LED,0) time.sleep(0.5) GPIO.output(LED,1) ...
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