adding some comments

This commit is contained in:
talksik
2023-05-04 14:33:05 -07:00
parent fde2704169
commit 76e6d2c106
2 changed files with 6 additions and 5 deletions
@@ -9,7 +9,7 @@ import RPi.GPIO as GPIO
import time
from ADCDevice import *
# define the pins connected to L293D
# define the pins connected to L293D
motoRPin1 = 13
motoRPin2 = 11
enablePin = 15
@@ -27,18 +27,18 @@ def setup():
"Program Exit. \n");
exit(-1)
global p
GPIO.setmode(GPIO.BOARD)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(motoRPin1,GPIO.OUT) # set pins to OUTPUT mode
GPIO.setup(motoRPin2,GPIO.OUT)
GPIO.setup(enablePin,GPIO.OUT)
p = GPIO.PWM(enablePin,1000) # creat PWM and set Frequence to 1KHz
p.start(0)
# mapNUM function: map the value from a range of mapping to another range.
def mapNUM(value,fromLow,fromHigh,toLow,toHigh):
return (toHigh-toLow)*(value-fromLow) / (fromHigh-fromLow) + toLow
# motor function: determine the direction and speed of the motor according to the input ADC value input
def motor(ADC):
value = ADC -128
@@ -54,6 +54,7 @@ def motor(ADC):
GPIO.output(motoRPin1,GPIO.LOW)
GPIO.output(motoRPin2,GPIO.LOW)
print ('Motor Stop...')
# the more you turn the potentiometer either direction, the faster the motor speed.
p.start(mapNUM(abs(value),0,128,0,100))
print ('The PWM duty cycle is %d%%\n'%(abs(value)*100/127)) # print PMW duty cycle.
@@ -67,7 +68,7 @@ def loop():
def destroy():
p.stop() # stop PWM
GPIO.cleanup()
if __name__ == '__main__': # Program entrance
print ('Program is starting ... ')
setup()
Binary file not shown.