0% found this document useful (0 votes)
5 views1 page

Raspberry Pi Motor Control Script

The document contains a Python script for controlling motors using the Raspberry Pi GPIO library. It defines a Motor class with methods to move the motor forward, backward, and stop, utilizing PWM for speed control. The script continuously moves three motors forward and backward with specified duty cycles and delays.

Uploaded by

chienvp0312
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Raspberry Pi Motor Control Script

The document contains a Python script for controlling motors using the Raspberry Pi GPIO library. It defines a Motor class with methods to move the motor forward, backward, and stop, utilizing PWM for speed control. The script continuously moves three motors forward and backward with specified duty cycles and delays.

Uploaded by

chienvp0312
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import RPi.

GPIO as GPIO
from time import sleep

[Link]([Link])
[Link](False)

class Motor():
def __init__(self, Ena, In1, In2):
[Link] = Ena
self.In1 = In1
self.In2 = In2
[Link]([Link], [Link])
[Link](self.In1, [Link])
[Link](self.In2, [Link])
[Link] = [Link]([Link], 100)
[Link](0)
def moveF(self, x = 50, t = 0):
[Link](self.In1, [Link])
[Link](self.In2, [Link])
[Link](x)
sleep(t)
def moveB(self, x = 50, t = 0):
[Link](self.In1, [Link])
[Link](self.In2, [Link])
[Link](x)
sleep(t)
def stop(self, t = 0):
[Link](0)
sleep(t)

motor1 = Motor(2, 3, 4)
motor2 = Motor(17, 22, 25)
motor3 = Motor(23, 24, 27)

while True:
[Link](30, 2)
[Link](30, 2)
[Link](30, 2)
[Link](2)
[Link](2)
[Link](2)
[Link](100, 2)
[Link](100, 2)
[Link](100, 2)
[Link](2)
[Link](2)
[Link](2)

You might also like