From 7fb06826cd5c03a3a27074eaefc288b1f9f5d386 Mon Sep 17 00:00:00 2001 From: Suhayl <838119509@qq.com> Date: Thu, 27 Sep 2018 10:38:57 +0800 Subject: [PATCH] Modified relay code. Modified the Python code of relay , compatible with python2 and python3. --- Code/Python_Code/14.1.1_Relay/Relay.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Code/Python_Code/14.1.1_Relay/Relay.py b/Code/Python_Code/14.1.1_Relay/Relay.py index b4124fa..3fa7a1d 100644 --- a/Code/Python_Code/14.1.1_Relay/Relay.py +++ b/Code/Python_Code/14.1.1_Relay/Relay.py @@ -3,7 +3,7 @@ # Filename : Relay.py # Description : Button control Relay and Motor # Author : freenove -# modification: 2018/09/26 +# modification: 2018/09/27 ######################################################################## import RPi.GPIO as GPIO import time @@ -20,15 +20,15 @@ def setup(): def loop(): relayState = False - lastChangeTime = long(round(time.time()*1000)) + lastChangeTime = round(time.time()*1000) buttonState = GPIO.HIGH lastButtonState = GPIO.HIGH reading = GPIO.HIGH while True: reading = GPIO.input(buttonPin) if reading != lastButtonState : - lastChangeTime = long(round(time.time()*1000)) - if ((long(round(time.time()*1000)) - lastChangeTime) > debounceTime): + lastChangeTime = round(time.time()*1000) + if ((round(time.time()*1000) - lastChangeTime) > debounceTime): if reading != buttonState : buttonState = reading; if buttonState == GPIO.LOW: