Created
December 6, 2017 10:00
-
-
Save erget/b09020cbfaebe9d574cb7a5ed5320bdc to your computer and use it in GitHub Desktop.
An example minimal LED driver using the GPIO Manager from FSE 2017
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# This file is part of FSE 2017. | |
# | |
# FSE 2017 is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# FSE 2017 is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with FSE 2017. If not, see <http://www.gnu.org/licenses/>. | |
"""Driver for a GPIO LED.""" | |
import time | |
import wiringpi | |
from gpio_manager import GPIO_Manager | |
class LED(GPIO_Manager): | |
"""Driver for an LED connected by GPIO.""" | |
_pin = 21 | |
_pins = [_pin] | |
def __init__(self): | |
super(LED, self).__init__() | |
wiringpi.pinMode(self._pin, wiringpi.OUTPUT) | |
def on(self): | |
wiringpi.digitalWrite(self._pin, wiringpi.OUTPUT) | |
def off(self): | |
wiringpi.digitalWrite(self._pin, wiringpi.INPUT) | |
if __name__ == "__main__": | |
with LED() as led: | |
while True: | |
led.on() | |
time.sleep(0.5) | |
led.off() | |
time.sleep(0.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment