Created
August 31, 2017 07:24
-
-
Save Ryomasao/f847689a561f887d5169224066e0dc38 to your computer and use it in GitHub Desktop.
レゴカーコントローラーの抜粋(コントローラー)
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
# -*- coding: utf-8 -*- | |
import wiringpi as pi | |
import sys | |
class LegoCarController: | |
''' | |
レゴカーを動かすためのクラス | |
前進と後退するためのDCモーター、ステアリング処理を行うサーボモータを制御している。 | |
制御するためのGPIOは、初期処理で固定で決めている。 | |
''' | |
def __init__(self): | |
pi.wiringPiSetupGpio() | |
#サーボモータを制御するクラス | |
self.servo_motor = NewServoMotor(18) | |
def handle(self, order): | |
''' | |
orderの値をもとに、まがる。 | |
:param order: | |
:return: | |
''' | |
if order == b'd' : | |
#右 | |
self.servo_motor.plusRotation() | |
elif order == b'a': | |
#左 | |
self.servo_motor.minusRotation() | |
else: | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment