# Exercise import lcddriver import RPi.GPIO as GPIO # For Digital I/O import os # For System Shutdown from time import gmtime, localtime, sleep, strftime # Instantiate display lcd = lcddriver.lcd() # Initialize display lcd.lcd_clear() # Initialize GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN, pull_up_down = GPIO.PUD_UP) # Persistent part of display (Lines 1-3) lcd.lcd_display_string(" HAM RADIO STATION", 1) lcd.lcd_display_string(" W A 4 E F S", 2) lcd.lcd_display_string(" ",3) # Variable part of display (Line 4 and Shutdown message) while (True): # Forever ... if (GPIO.input(17) == 1): # Shutdown button pressed # Shutdown message lcd.lcd_display_string("** Shutting down! **", 1) lcd.lcd_display_string("Please wait 1 minute", 2) lcd.lcd_display_string("before disconnecting", 3) lcd.lcd_display_string("power. ", 4) sleep(1) # Make sure display has painted os.system("sudo shutdown --poweroff now") quit() # Enable either Universal Time or Local Time by commenting-out the other lcd.lcd_display_string(strftime("%d %b %Y %H:%M:%S", gmtime()),4) # lcd.lcd_display_string(strftime("%d %b %Y %H:%M:%S", localtime()),4) sleep(.05)