2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
import PySimpleGUI27 as sg
|
|
|
|
else:
|
|
|
|
import PySimpleGUI as sg
|
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-24 22:01:00 +00:00
|
|
|
[rg.ReadButton('Switch LED')],
|
|
|
|
[rg.ReadButton('Flash LED')],
|
|
|
|
[rg.Exit()]]
|
2018-09-04 23:43:22 +00:00
|
|
|
|
2018-09-24 22:01:00 +00:00
|
|
|
window = rg.Window('Raspberry Pi GUI', grab_anywhere=False).Layout(layout)
|
2018-09-04 23:43:22 +00:00
|
|
|
|
|
|
|
while True:
|
2018-09-24 22:01:00 +00:00
|
|
|
button, values = window.Read()
|
2018-09-04 23:43:22 +00:00
|
|
|
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-24 22:01:00 +00:00
|
|
|
window.FindElement('output').Update(SwitchLED())
|
2018-09-04 23:43:22 +00:00
|
|
|
elif button is 'Flash LED':
|
2018-09-24 22:01:00 +00:00
|
|
|
window.FindElement('output').Update('LED is Flashing')
|
|
|
|
window.ReadNonBlocking()
|
2018-09-04 23:43:22 +00:00
|
|
|
FlashLED()
|
2018-09-24 22:01:00 +00:00
|
|
|
window.FindElement('output').Update('')
|
2018-09-04 23:43:22 +00:00
|
|
|
|
2018-09-20 14:41:47 +00:00
|
|
|
rg.Popup('Done... exiting')
|