def main():
    """ メイン関数 """
    # 接続ピン
    PIN_AIN1 = 6
    PIN_AIN2 = 5
    PIN_BIN1 = 26
    PIN_BIN2 = 27
    # 左右モーター設定(PWM)
    motors = Robot(left=(PIN_AIN1, PIN_AIN2),
                   right=(PIN_BIN1, PIN_BIN2),
                   pwm=True)

    # 1秒毎の正負パルス値の信号源
    dirleft = post_delayed(scaled(alternating_values(True), -1, 1), 1)
    dirright = post_delayed(scaled(alternating_values(False), -1, 1), 1)

    # 左右モーターに信号源を接続
    motors.source = zip(dirleft, dirright)

    # 停止(Ctrl+c)まで待機
    pause()
Exemple #2
0
from signal import pause
import atexit
import gpiozero
from gpiozero.tools import scaled, negated

robot = gpiozero.Robot(left=(27, 17), right=(24, 23))
left_line_sensor = gpiozero.LineSensor(5)
right_line_sensor = gpiozero.LineSensor(6)
# Ensure it will stop
atexit.register(robot.stop)

robot.left_motor.source = scaled(negated(left_line_sensor), -0.3, 0.4)
robot.right_motor.source = scaled(negated(right_line_sensor), -0.3, 0.4)

pause()
Exemple #3
0
def flicker():
 for led in tree:
    led.source_delay = 0.1
    led.source = scaled(random_values(),0,times)
from signal import pause
import atexit
import gpiozero
from gpiozero.tools import scaled, negated

robot = gpiozero.Robot(left=(27, 17), right=(24, 23))
left_obstacle_sensor = gpiozero.DigitalInputDevice(13)
right_obstacle_sensor = gpiozero.DigitalInputDevice(26)
# Ensure it will stop
atexit.register(robot.stop)

robot.right_motor.source = scaled(left_obstacle_sensor, -1, 1)
robot.left_motor.source = scaled(right_obstacle_sensor, -1, 1)

pause()
from gpiozero import Robot, MCP3008
from gpiozero.tools import scaled
from signal import pause

robot = Robot(left=(4, 14), right=(17, 18))

left_pot = MCP3008(0)
right_pot = MCP3008(1)

robot.source = zip(scaled(left_pot, -1, 1), scaled(right_pot, -1, 1))

pause()
Exemple #6
0
from gpiozero import Robot, MCP3008
from gpiozero.tools import scaled
from signal import pause

robot = Robot(left=(4, 14), right=(17, 18))

left = MCP3008(0)
right = MCP3008(1)

robot.source = zip(scaled(left.values, -1, 1), scaled(right.values, -1, 1))

pause()