-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38438ed
commit 0c330da
Showing
5 changed files
with
111 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import time | ||
import zorg | ||
|
||
|
||
def buzz(my): | ||
while True: | ||
my.buzzer.toggle() | ||
time.sleep(0.5) | ||
|
||
robot = zorg.robot({ | ||
"name": "Test", | ||
"connections": { | ||
"edison": { | ||
"adaptor": "zorg_edison.Edison", | ||
}, | ||
}, | ||
"devices": { | ||
"buzzer": { | ||
"connection": "edison", | ||
"driver": "zorg_gpio.Buzzer", | ||
"pin": 4, # Digital pin 4 | ||
}, | ||
}, | ||
"work": buzz, | ||
}) | ||
|
||
robot.start() |
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from zorg.driver import Driver | ||
|
||
|
||
class Buzzer(Driver): | ||
|
||
def __init__(self, options, connection): | ||
super(Buzzer, self).__init__(options, connection) | ||
|
||
self.current_state = False | ||
|
||
self.commands = [ | ||
"set_state", | ||
"is_on", | ||
"turn_on", | ||
"turn_off", | ||
"toggle", | ||
] | ||
|
||
def set_state(self, state): | ||
""" | ||
State should be a 1 or a 0. | ||
""" | ||
self.current_state = (state == 1) | ||
self.connection.digital_write(self.pin, state) | ||
|
||
def is_on(self): | ||
return self.current_state | ||
|
||
def turn_on(self): | ||
self.current_state = True | ||
self.connection.digital_write(self.pin, 1) | ||
|
||
def turn_off(self): | ||
self.current_state = False | ||
self.connection.digital_write(self.pin, 0) | ||
|
||
def toggle(self): | ||
if self.is_on(): | ||
self.turn_off() | ||
else: | ||
self.turn_on() |