-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Garage Door State Machine initial version complete
It now tells you if the door is open or closed. And by making the door a class, in the future I could design this to give state of all doors.
- Loading branch information
Eric Mesa
committed
Mar 29, 2020
1 parent
6813b82
commit 2be96db
Showing
2 changed files
with
28 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,28 @@ | ||
"""Class representing a Garage Door alarm.""" | ||
|
||
import RPi.GPIO as GPIO | ||
|
||
|
||
class door(): | ||
def __init__(self, pin: int): | ||
self.state = "closed" | ||
GPIO.setmode(GPIO.BOARD) | ||
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) | ||
self.state: int = 1 | ||
self.pin = pin | ||
self.state_definition = {1:"closed", 0:"open"} | ||
|
||
|
||
def _check_pin(self): | ||
current_state = GPIO.input(self.pin) | ||
return current_state | ||
|
||
|
||
def has_state_changed() -> bool: | ||
return True | ||
def has_state_changed(self) -> tuple: | ||
current_state = self._check_pin() | ||
#print(f"For debugging: \nCurrent state: {current_state}. \nself.state: {self.state}") | ||
if current_state != self.state: | ||
self.state = current_state | ||
state_in_words = self.state_definition[self.state] | ||
return True, state_in_words | ||
else: | ||
return False, "unchanged" |