diff py/gpio_rpi.py @ 527:dd8895652485

porting to asyncio
author Matt Johnston <matt@ucc.asn.au>
date Fri, 20 Mar 2015 20:12:25 +0800
parents
children d9b819dcac53
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/py/gpio_rpi.py	Fri Mar 20 20:12:25 2015 +0800
@@ -0,0 +1,21 @@
+import os
+
+import RPi.GPIO as GPIO
+
+from utils import L,D,EX,W
+
+__all__ = ["Gpio"]
+
+class Gpio(object):
+	def __init__(self, pin, name):
+		self.pin = pin
+		self.name = name
+		GPIO.setmode(GPIO.BOARD)
+		GPIO.setup(self.pin, GPIO.OUT)
+
+	def turn(self, value):
+		self.state = bool(value)
+		GPIO.output(self.pin, self.state)
+
+	def get_state(self):
+		return GPIO.input(self.pin)