Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- from flask import Flask, render_template
- import Adafruit_BBIO.GPIO as GPIO
- import Adafruit_BBIO.PWM as PWM
- from time import sleep
- class Motor:
- def __init__(self, dir_pin, pwm_pin, pwm_freq):
- self.dir_pin = dir_pin
- self.pwm_pin = pwm_pin
- self.value = 0
- PWM.start(pwm_pin, 0, pwm_freq)
- GPIO.setup(dir_pin, GPIO.OUT)
- def set(self, value):
- if value == self.value:
- return
- assert -100 <= value <= 100
- if (value < 0) != (self.value < 0):
- # changing direction
- PWM.set_duty_cycle(self.pwm_pin, 0)
- GPIO.output(self.dir_pin, value < 0)
- PWM.set_duty_cycle(self.pwm_pin, abs(value))
- self.value = value
- motor1 = Motor(dir_pin="P8_18", pwm_pin="P9_16", pwm_freq=1000)
- # motor2 = Motor(dir_pin="P8_16", pwm_pin="P9_14", pwm_freq=1000)
- # motor3 = Motor(dir_pin="P8_14", pwm_pin="P8_13", pwm_freq=1000)
- # motor4 = Motor(dir_pin="P8_26", pwm_pin="P8_19", pwm_freq=1000)
- def set_motorOne(v1):
- motor1.set(v1)
- ...
- v1("0", 0)
- v1('40', 40)
- v1('50', 50)
- ...
Add Comment
Please, Sign In to add comment