From e951297ff18ade63a475da0982524432fa4e86df Mon Sep 17 00:00:00 2001 From: Suhayl <838119509@qq.com> Date: Thu, 11 Apr 2019 11:16:42 +0800 Subject: [PATCH] Optimized code. Optimized code. Remove some redundant code. --- Code/C_Code/13.1.1_Motor/Motor.c | 2 +- Code/Python_Code/03.1.1_LightWater/LightWater.py | 2 +- Code/Python_Code/24.1.1_UltrasonicRanging/UltrasonicRanging.py | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Code/C_Code/13.1.1_Motor/Motor.c b/Code/C_Code/13.1.1_Motor/Motor.c index 5a63b9b..fa28559 100644 --- a/Code/C_Code/13.1.1_Motor/Motor.c +++ b/Code/C_Code/13.1.1_Motor/Motor.c @@ -43,7 +43,7 @@ void motor(int ADC){ digitalWrite(motorPin2,LOW); printf("Motor Stop...\n"); } - softPwmWrite(enablePin,map(abs(value),0,128,0,255)); + softPwmWrite(enablePin,map(abs(value),0,128,0,100)); printf("The PWM duty cycle is %d%%\n",abs(value)*100/127);//print the PMW duty cycle } int main(void){ diff --git a/Code/Python_Code/03.1.1_LightWater/LightWater.py b/Code/Python_Code/03.1.1_LightWater/LightWater.py index 1212533..860c1fc 100644 --- a/Code/Python_Code/03.1.1_LightWater/LightWater.py +++ b/Code/Python_Code/03.1.1_LightWater/LightWater.py @@ -23,7 +23,7 @@ def loop(): GPIO.output(pin, GPIO.LOW) time.sleep(0.1) GPIO.output(pin, GPIO.HIGH) - for pin in ledPins[10:0:-1]: #make led on from right to left + for pin in ledPins[::-1]: #make led on from right to left GPIO.output(pin, GPIO.LOW) time.sleep(0.1) GPIO.output(pin, GPIO.HIGH) diff --git a/Code/Python_Code/24.1.1_UltrasonicRanging/UltrasonicRanging.py b/Code/Python_Code/24.1.1_UltrasonicRanging/UltrasonicRanging.py index 0115c04..ee82486 100644 --- a/Code/Python_Code/24.1.1_UltrasonicRanging/UltrasonicRanging.py +++ b/Code/Python_Code/24.1.1_UltrasonicRanging/UltrasonicRanging.py @@ -40,7 +40,6 @@ def setup(): GPIO.setup(echoPin, GPIO.IN) # def loop(): - GPIO.setup(11,GPIO.IN) while(True): distance = getSonar() print ("The distance is : %.2f cm"%(distance))