Skip to content

Instantly share code, notes, and snippets.

@daniel-obrien
Forked from deepaksinghvi/deepakmotor.py
Created January 11, 2017 18:58
Show Gist options
  • Save daniel-obrien/f621bd49c2e68aaba7f6da94184fcf3f to your computer and use it in GitHub Desktop.
Save daniel-obrien/f621bd49c2e68aaba7f6da94184fcf3f to your computer and use it in GitHub Desktop.
Program to control the DC motor using RaspberryPI and L298N Motor Controller
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BOARD)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
def forward(x):
GPIO.output(13, GPIO.HIGH)
sleep(x)
GPIO.output(13, GPIO.LOW)
def reverse(x):
GPIO.output(15, GPIO.HIGH)
sleep(x)
GPIO.output(15, GPIO.LOW)
forward(3)
sleep(0.5)
reverse(3)
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment