Skip to content

Commit 5c29db6

Browse files
committed
ATLEDGE-396 Fix behavior of analogWrite() on non PWM pins
For all non PWM pins, the behavior of calling analogWrite() should be logic 0 if the value is 127 or less. For values of 128 or above, the pin should go to logic 1.
1 parent 7afbd91 commit 5c29db6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cores/arduino/wiring_analog.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,18 @@ static inline uint32_t mapResolution(uint32_t value, uint32_t from, uint32_t to)
5151

5252
void analogWrite(uint8_t pin, int val)
5353
{
54-
if (! digitalPinHasPWM(pin)) return;
54+
if (! digitalPinHasPWM(pin))
55+
{
56+
if(val > 127)
57+
{
58+
digitalWrite(pin, HIGH);
59+
}
60+
else
61+
{
62+
digitalWrite(pin, LOW);
63+
}
64+
return;
65+
}
5566

5667
if (val <= 0) {
5768
/* Use GPIO for 0% duty cycle (always off) */

0 commit comments

Comments
 (0)