Hi guys,
I am trying to use a pushbutton and measure its pulse by using pulseIn. The pushbutton is connected to 5v with a pullup resistor. Then, use the measured pulse and convert it to the variable that can control the PWM duty cycle. Then, I can use this variable with analogWrite to control the led.
duration = pulseIn(button, HIGH);
I know I can measure the pulse by this. Then I don't know how to convert it.
note: that variable should between 0 and 255.
PLS help, thank you guys
If the button makes the pin pulse LOW, shouldn't you be looking for a LOW pulse instead of a HIGH pulse?
What range of microseconds do you want to map to the PWM range (0-255). Maybe one 2.55 seconds? 2550000 microseconds? Note, there is a (default of) 1 second timeout on pulseIn(). Add a third argument if you want to allow more time.