I have been struggling all day with two things in my program(s). This is trying to use PWM to control a motor.
Problem 1] Incrementing the PWM% by 15% each time the button is pressed. The error that I am getting is: File "/home/pi/rc-car/app.py", line 76, in Up_15 PWM_value = PWM_value + PWM_increment UnboundLocalError: local variable 'PWM_value' referenced before assignment The code for this is: @app.route('/up_15/') def Up_15(): global PWM_Value PWM_value = PWM_value + PWM_increment duty_cycle_percentage = PWM_value * 100 / ms_per_cycle print("Duty Cycle[F]: " + str(duty_cycle_percentage)) pwm.start(duty_cycle_percentage) time.sleep(.5) pwm.ChangeDutyCycle(0) return render_template('index.html', PWM_value) where these are initialized: PWM_Stop = 0 PWM_value = 0 PWM_increment = 15 The second thing that I am trying to do is pass the parameter PWM_Value back to the HTML and then display it. I see an error there already in a lc 'v'. I cannot find any help on-line for this. The particular bit of the HTML that calls the Python is: <div class="grid-container"> <div class="grid-item"></div> <div class="grid-item"> <a href="/up_15/" data-toggle="tooltip" title="Forward" class="btn btn-success">UP +15%</a> </div> <div class="grid-item"></div> In this line following: <a href="/up_15/" data-toggle="tooltip" title="Forward" class="btn btn-success">UP +15%</a> These bits were there in the program that I stole this stuff from: data-toggle="tooltip" title="Forward" class="btn btn-success" so I don't know what they do aside from nothing obvious. Thanks for any help and advice. Already seen one possibility: The HTML is 'up_15' and the Python it calls is 'Up_15'. But that must work or I wouldn't get the error above. Peter M. -- Next meeting: BEC, Bournemouth, Tuesday, 2019-09-03 20:00 Check to whom you are replying Meetings, mailing list, IRC, ... http://dorset.lug.org.uk/ New thread, don't hijack: mailto:dorset@mailman.lug.org.uk