changeset 0:0eaad3e87a53

Initial commit
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sat, 21 Nov 2015 18:46:26 +0100
parents
children d386d8a70bdc
files .hgignore servo.py
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Sat Nov 21 18:46:26 2015 +0100
@@ -0,0 +1,5 @@
+syntax: glob
+*~
+.*.swp
+*.DS_Store
+doc/_build
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/servo.py	Sat Nov 21 18:46:26 2015 +0100
@@ -0,0 +1,17 @@
+import smbus
+
+import struct
+import math
+
+
+class Servos(object):
+    def __init__(self, address=0x04, bus=1):
+        self.address = address
+        self.bus = smbus.SMBus(bus)
+
+    def move(self, servo, radians=None, degrees=None):
+        if radians is None:
+            radians = math.radians(degrees)
+        self.bus.write_block_data(self.address, servo,
+            [ord(b) for b in struct.pack('<f', radians)])
+