Advertisement
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 Motors:
- 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 = Motors(dir_pin="P8_18", pwm_pin="P9_16", pwm_freq=1500)
- motor2 = Motors(dir_pin="P8_16", pwm_pin="P9_14", pwm_freq=1500)
- motor3 = Motors(dir_pin="P8_14", pwm_pin="P8_13", pwm_freq=1500)
- motor4 = Motors(dir_pin="P8_26", pwm_pin="P8_19", pwm_freq=1500)
- def set_motorOne(v1):
- motor1.set(v1)
- def set_motorTwo(v2):
- motor2.set(v2)
- def set_motorThree(v3):
- motor3.set(v3)
- def set_motorFour(v4):
- motor4.set(v4)
- app = Flask(__name__)
- @app.route("/")
- def homepage(title="homepage"):
- return render_template("BootGoOne.html", title=title)
- def add_motors_routeOne(state, v1):
- @app.route("/" + state, endpoint=state)
- def handlerOne():
- set_motorOne(v1)
- return homepage(title=state)
- add_motors_routeOne('0', 0)
- add_motors_routeOne('10', 10)
- add_motors_routeOne('20', 20)
- add_motors_routeOne('30', 30)
- add_motors_routeOne('40', 40)
- add_motors_routeOne('50', 50)
- add_motors_routeOne('60', 60)
- add_motors_routeOne('70', 70)
- add_motors_routeOne('80', 80)
- add_motors_routeOne('90', 90)
- add_motors_routeOne('100', 100)
- add_motors_routeOne('-4', -4)
- add_motors_routeOne('-10', -10)
- add_motors_routeOne('-20', -20)
- add_motors_routeOne('-30', -30)
- add_motors_routeOne('-40', -40)
- add_motors_routeOne('-50', -50)
- add_motors_routeOne('-60', -60)
- add_motors_routeOne('-70', -70)
- add_motors_routeOne('-80', -80)
- add_motors_routeOne('-90', -90)
- add_motors_routeOne('-100', -100)
- def add_motors_routeTwo(state, v2):
- @app.route("/" + state, endpoint=state)
- def handlerTwo():
- set_motorTwo(v2)
- return homepage(title=state)
- add_motors_routeTwo('1', 1)
- add_motors_routeTwo('11', 11)
- add_motors_routeTwo('21', 21)
- add_motors_routeTwo('31', 31)
- add_motors_routeTwo('41', 41)
- add_motors_routeTwo('51', 51)
- add_motors_routeTwo('61', 61)
- add_motors_routeTwo('71', 71)
- add_motors_routeTwo('81', 81)
- add_motors_routeTwo('91', 91)
- add_motors_routeTwo('-1', -1)
- add_motors_routeTwo('-11', -11)
- add_motors_routeTwo('-21', -21)
- add_motors_routeTwo('-31', -31)
- add_motors_routeTwo('-41', -41)
- add_motors_routeTwo('-51', -51)
- add_motors_routeTwo('-61', -61)
- add_motors_routeTwo('-71', -71)
- add_motors_routeTwo('-81', -81)
- add_motors_routeTwo('-91', -91)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement