0

For now I'm doing a project involving a Raspberry Pi and a push button. I managed to control LED with the push button using PWM where as we pressed the button, the duty cycle value increase. However, I want the duty cycle value keep on increasing as I keep on press the push button switch. Right now, the value only increase one time only even though I keep press the push button switch without release. Is there any way to do that?

This is the code I made for now

button1State=GPIO.input(button1)
button2State=GPIO.input(button2)
#print('Button States', button1State, button2State)

if button1StateOld==0 and button1State==1:
    DC=DC+10
    #print("Heating")
    
if button2StateOld==0 and button2State==1:
    DC=DC-10
    #print("De-Heating")
if DC>100:
    DC=100
if DC<0:
    DC=0
pi_pwm.ChangeDutyCycle(DC)
button1StateOld=button1State
button2StateOld=button2State
New contributor
Haziq Hasbulah is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1

0

Browse other questions tagged or ask your own question.