Skip to content

Commit

Permalink
Servo (#4)
Browse files Browse the repository at this point in the history
* 微修正

* floatだった

* デストラクタ定義

* __del__は明示的に呼ばなくてもよいです
  • Loading branch information
RyosukeSasaki authored and naoki-cpp committed Jul 12, 2019
1 parent 4c0802b commit f98e42b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions raspberry_pi/lib/servo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
rotation backward - nuetral - forward
"""
import RPi.GPIO as GPIO
import time
import sys

__all__ = ['servo']
Expand All @@ -30,14 +29,15 @@ def __enter__(self):
def rotate(self, duty):
self.srv.ChangeDutyCycle(duty)

def __exit__(self, exception_type, exception_value, traceback):
def __del__(self):
self.srv.stop()
GPIO.cleanup(self.pin)

def __exit__(self, exception_type, exception_value, traceback):
pass

if __name__ == "__main__":
args = sys.argv
with servo(int(args[1])) as sv:
sv.rotate(5)
time.sleep(1)
sv.rotate(10)
time.sleep(1)
while True:
sv.rotate(float(args[2]))

0 comments on commit f98e42b

Please sign in to comment.