Update NewMotorFunc.py
This commit is contained in:
parent
3c6ed80d8e
commit
82d9947ef5
1 changed files with 78 additions and 72 deletions
|
@ -1,9 +1,10 @@
|
|||
import RPi.GPIO as GPIO
|
||||
mport RPi.GPIO as GPIO
|
||||
import pyrebase # u need to install Pyrebase module firstly
|
||||
from time import sleep
|
||||
|
||||
|
||||
class Motor:
|
||||
|
||||
|
||||
print("Starting of the program")
|
||||
|
||||
def __init__(self):
|
||||
|
@ -45,6 +46,8 @@ class Motor:
|
|||
self.motorStop=False
|
||||
self.alarmStop=False
|
||||
|
||||
|
||||
|
||||
# new update motor and alarm functions, are able to connect embedded system throught firebase
|
||||
|
||||
def start_motor(self):
|
||||
|
@ -55,11 +58,13 @@ class Motor:
|
|||
|
||||
self.motorStop=self.stop_motor()
|
||||
|
||||
|
||||
def stop_motor(self):
|
||||
|
||||
database = self.firebase.database() # get alarm on/off signal from firebase
|
||||
signals = database.child("signal")
|
||||
motorSignal = signals.child("1").child("motor").get().val()
|
||||
motorSignal = signals.child("power").get().val()
|
||||
|
||||
|
||||
if (motorSignal=="off") or (not GPIO.input(13)):
|
||||
print("stopping motor...")
|
||||
|
@ -81,6 +86,7 @@ class Motor:
|
|||
print("motor is turned on")
|
||||
return False
|
||||
|
||||
|
||||
def start_alarm(self):
|
||||
|
||||
self.alarmStop=self.stop_alarm()
|
||||
|
@ -90,12 +96,11 @@ class Motor:
|
|||
self.alarmStop=self.stop_alarm() # infinitely check if alarmStop True
|
||||
|
||||
# break the loop if alarm is turned off
|
||||
|
||||
def stop_alarm(self):
|
||||
|
||||
database = self.firebase.database() # get alarm on/off signal from firebase
|
||||
signals = database.child("signal")
|
||||
alarmSignal = signals.child("1").child("alarm").get().val()
|
||||
alarmSignal = signals.child("alarm").get().val()
|
||||
|
||||
if alarmSignal=="off":
|
||||
print("Alarm turning off...")
|
||||
|
@ -109,10 +114,11 @@ class Motor:
|
|||
return False
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if _name__=="__main_":
|
||||
|
||||
#print("Execute function...")
|
||||
|
||||
|
||||
motor1=Motor()
|
||||
|
||||
while True: # turn on the system forever
|
||||
|
|
Loading…
Reference in a new issue