2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-04 23:43:22 +00:00
|
|
|
import time
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
# App for Raspberry Pi.
|
|
|
|
|
2019-06-26 15:43:36 +00:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
|
|
|
|
class GPIO():
|
|
|
|
LOW = 0
|
|
|
|
HIGH = 1
|
|
|
|
BCM = OUT = 0
|
|
|
|
current_value = 0
|
2019-10-23 20:10:03 +00:00
|
|
|
|
2019-06-26 15:43:36 +00:00
|
|
|
@classmethod
|
|
|
|
def setmode(self, mode):
|
|
|
|
return
|
2019-10-23 20:10:03 +00:00
|
|
|
|
2019-06-26 15:43:36 +00:00
|
|
|
@classmethod
|
|
|
|
def setup(self, arg1, arg2):
|
|
|
|
return
|
2019-10-23 20:10:03 +00:00
|
|
|
|
2019-06-26 15:43:36 +00:00
|
|
|
@classmethod
|
|
|
|
def output(self, port, value):
|
|
|
|
self.current_value = value
|
2019-10-23 20:10:03 +00:00
|
|
|
|
2019-06-26 15:43:36 +00:00
|
|
|
@classmethod
|
|
|
|
def input(self, port):
|
|
|
|
return self.current_value
|
|
|
|
else:
|
|
|
|
import RPi.GPIO as GPIO
|
|
|
|
|
2018-09-04 23:43:22 +00:00
|
|
|
# determine that GPIO numbers are used:
|
|
|
|
GPIO.setmode(GPIO.BCM)
|
|
|
|
GPIO.setup(14, GPIO.OUT)
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
|
2018-09-04 23:43:22 +00:00
|
|
|
def SwitchLED():
|
2019-06-26 15:43:36 +00:00
|
|
|
varLedStatus = GPIO.input(14)
|
2018-09-12 20:46:35 +00:00
|
|
|
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)
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
|
|
|
|
layout = [[sg.Text('Raspberry Pi LEDs')],
|
|
|
|
[sg.Text('', size=(20, 1), key='output')],
|
|
|
|
[sg.Button('Switch LED')],
|
|
|
|
[sg.Button('Flash LED')],
|
|
|
|
[sg.Exit()]]
|
2018-09-04 23:43:22 +00:00
|
|
|
|
2019-06-26 15:43:36 +00:00
|
|
|
window = sg.Window('Raspberry Pi GUI', layout, grab_anywhere=False)
|
2018-09-04 23:43:22 +00:00
|
|
|
|
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
2020-05-07 10:22:59 +00:00
|
|
|
if event in (sg.WIN_CLOSED, 'Exit'):
|
2018-09-04 23:43:22 +00:00
|
|
|
break
|
2018-09-12 20:46:35 +00:00
|
|
|
|
2019-06-26 15:09:42 +00:00
|
|
|
if event == 'Switch LED':
|
2019-10-23 20:10:03 +00:00
|
|
|
window['output'].update(SwitchLED())
|
2019-06-26 15:09:42 +00:00
|
|
|
elif event == 'Flash LED':
|
2019-10-23 20:10:03 +00:00
|
|
|
window['output'].update('LED is Flashing')
|
|
|
|
window.refresh()
|
2018-09-04 23:43:22 +00:00
|
|
|
FlashLED()
|
2019-10-23 20:10:03 +00:00
|
|
|
window['output'].update('')
|
2018-09-04 23:43:22 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window.close()
|