arduino / arduino/ArduinoCore-avr
Calling digitalRead() should not clear PWM setting
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
comment out this line in
```
int digitalRead(uint8_t pin)
...
// if (timer != NOT_ON_TIMER) turnOffPWM(timer);
...
```
While writing a sketch for beginners, I was doing a digital read of a PWM output
And it did not do as I expected.
What I was expecting was HIGH and LOW in about the PWM ratio
But always got LOW.
Then found this in the code
I don't see any reason to override a uses PWM setting just because their code asks for a read.
matthew
```
int digitalRead(uint8_t pin)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
if (port == NOT_A_PIN) return LOW;
// If the pin that support PWM output, we need to turn it off
// before getting a digital reading.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
if (*portInputRegister(port) & bit) return HIGH;
return LOW;
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.