2018-09-06 20:20:37 +00:00
|
|
|
import PySimpleGUI as rg
|
2018-09-04 23:43:22 +00:00
|
|
|
|
|
|
|
# GUI for switching an LED on and off to GPIO14
|
|
|
|
|
|
|
|
# GPIO and time library:
|
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
import time
|
|
|
|
|
|
|
|
# determine that GPIO numbers are used:
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
|
|
GPIO.setup(14, GPIO.OUT)
|
|
|
|
|
|
|
|
def SwitchLED():
|
|
|
|
varLEDStatus = GPIO.input(14)
|
2018-09-12 20:46:35 +00:00
|
|
|
varLedStatus = 0
|
|
|
|
if varLedStatus == 0:
|
2018-09-04 23:43:22 +00:00
|
|
|
GPIO.output(14, GPIO.HIGH)
|
|
|
|
return "LED is switched ON"
|
|
|
|
else:
|
|
|
|
GPIO.output(14, GPIO.LOW)
|
|
|
|
return "LED is switched OFF"
|
|
|
|
|
|
|
|
|
|
|
|
def FlashLED():
|
|
|
|
for i in range(5):
|
|
|
|
GPIO.output(14, GPIO.HIGH)
|
|
|
|
time.sleep(0.5)
|
|
|
|
GPIO.output(14, GPIO.LOW)
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
2018-09-06 20:20:37 +00:00
|
|
|
layout = [[rg.T('Raspberry Pi LEDs')],
|
2018-09-12 20:46:35 +00:00
|
|
|
[rg.T('', size=(14, 1), key='output')],
|
2018-09-06 20:20:37 +00:00
|
|
|
[rg.ReadFormButton('Switch LED')],
|
|
|
|
[rg.ReadFormButton('Flash LED')],
|
|
|
|
[rg.Exit()]
|
2018-09-04 23:43:22 +00:00
|
|
|
]
|
|
|
|
|
2018-09-12 20:46:35 +00:00
|
|
|
form = rg.FlexForm('Raspberry Pi GUI', grab_anywhere=False)
|
2018-09-04 23:43:22 +00:00
|
|
|
form.Layout(layout)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
button, values = form.Read()
|
|
|
|
if button is None:
|
|
|
|
break
|
2018-09-12 20:46:35 +00:00
|
|
|
|
2018-09-04 23:43:22 +00:00
|
|
|
if button is 'Switch LED':
|
2018-09-12 20:46:35 +00:00
|
|
|
form.FindElement('output').Update(SwitchLED())
|
2018-09-04 23:43:22 +00:00
|
|
|
elif button is 'Flash LED':
|
2018-09-12 20:46:35 +00:00
|
|
|
form.FindElement('output').Update('LED is Flashing')
|
2018-09-04 23:43:22 +00:00
|
|
|
form.ReadNonBlocking()
|
|
|
|
FlashLED()
|
2018-09-12 20:46:35 +00:00
|
|
|
form.FindElement('output').Update('')
|
2018-09-04 23:43:22 +00:00
|
|
|
|
2018-09-06 20:20:37 +00:00
|
|
|
rg.MsgBox('Done... exiting')
|