Skip to content

Instantly share code, notes, and snippets.

@myselfgautham
Last active April 26, 2024 12:53
Show Gist options
  • Save myselfgautham/f6e9179025304e37b0d139eef7430023 to your computer and use it in GitHub Desktop.
Save myselfgautham/f6e9179025304e37b0d139eef7430023 to your computer and use it in GitHub Desktop.
Response To Issue Regarding PyFirmata #130
# Imports
import pyfirmata
from time import sleep
# Board Code
board = pyfirmata.ArduinoMega('/dev/tty.usbmodem1301')
print("Communication Successfully Started")
# Pin Variables
PWM1 = board.get_pin('d:4:p')
PWM2 = board.get_pin('d:5:p')
M1INA = board.get_pin('d:22:o')
M1INB = board.get_pin('d:23:o')
M2INA = board.get_pin('d:24:o')
M2INB = board.get_pin('d:25:o')
# Power Of All The Motors
def powerOffAllMotors():
M1INA.write(0)
M1INB.write(0)
M2INA.write(0)
M2INB.write(0)
return None
# Motion Code Blocks
def forwards(vel):
M1INA.write(1)
M1INB.write(0)
M2INA.write(1)
M2INB.write(0)
PWM1.write(vel)
PWM2.write(vel)
def backwards(vel):
M1INA.write(0)
M1INB.write(1)
M2INA.write(0)
M2INB.write(1)
PWM1.write(vel)
PWM2.write(vel)
def right(vel):
M1INA.write(1)
M1INB.write(0)
M2INA.write(0)
M2INB.write(1)
PWM1.write(vel)
PWM2.write(vel/2)
def left(vel):
M1INA.write(0)
M1INB.write(1)
M2INA.write(1)
M2INB.write(0)
v = max(0, min(int(vel / 100 * 255), 255))
PWM1.write(vel/2)
PWM2.write(vel)
if __name__ == "__main__":
# Power Of All Motors
powerOffAllMotors()
# Your Code Here I Beleive
forwards(100)
sleep(6)
print("Done Going Forwards!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment