diff --git a/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/13.1.1_Motor/Motor.py b/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/13.1.1_Motor/Motor.py index 16dd554..4562c6a 100644 --- a/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/13.1.1_Motor/Motor.py +++ b/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/13.1.1_Motor/Motor.py @@ -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() diff --git a/voice-server/output.wav b/voice-server/output.wav index e2f4fb1..8832d8a 100644 Binary files a/voice-server/output.wav and b/voice-server/output.wav differ