Merge pull request #1637 from PySimpleGUI/Dev-latest

Removed ambiguous variable.  Made a simulated GPIO class if platform …
This commit is contained in:
MikeTheWatchGuy 2019-06-26 11:44:22 -04:00 committed by GitHub
commit 8ab6506de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 6 deletions

View File

@ -7,16 +7,37 @@ else:
# GUI for switching an LED on and off to GPIO14 # GUI for switching an LED on and off to GPIO14
# GPIO and time library: # GPIO and time library:
import RPi.GPIO as GPIO
import time import time
if sys.platform == 'win32':
from random import randint
class GPIO():
LOW = 0
HIGH = 1
BCM = OUT = 0
current_value = 0
@classmethod
def setmode(self, mode):
return
@classmethod
def setup(self, arg1, arg2):
return
@classmethod
def output(self, port, value):
self.current_value = value
@classmethod
def input(self, port):
return self.current_value
else:
import RPi.GPIO as GPIO
# determine that GPIO numbers are used: # determine that GPIO numbers are used:
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
GPIO.setup(14, GPIO.OUT) GPIO.setup(14, GPIO.OUT)
def SwitchLED(): def SwitchLED():
varLEDStatus = GPIO.input(14) varLedStatus = GPIO.input(14)
varLedStatus = 0
if varLedStatus == 0: if varLedStatus == 0:
GPIO.output(14, GPIO.HIGH) GPIO.output(14, GPIO.HIGH)
return "LED is switched ON" return "LED is switched ON"
@ -33,16 +54,16 @@ def FlashLED():
time.sleep(0.5) time.sleep(0.5)
layout = [[sg.T('Raspberry Pi LEDs')], layout = [[sg.T('Raspberry Pi LEDs')],
[sg.T('', size=(14, 1), key='output')], [sg.T('', size=(20, 1), key='output')],
[sg.Button('Switch LED')], [sg.Button('Switch LED')],
[sg.Button('Flash LED')], [sg.Button('Flash LED')],
[sg.Exit()]] [sg.Exit()]]
window = sg.Window('Raspberry Pi GUI', grab_anywhere=False).Layout(layout) window = sg.Window('Raspberry Pi GUI', layout, grab_anywhere=False)
while True: while True:
event, values = window.Read() event, values = window.Read()
if event is None: if event in (None, 'Exit'):
break break
if event == 'Switch LED': if event == 'Switch LED':