arduino / arduino/ArduinoCore-megaavr
Unexpected digitalWrite behavior when writing numerical values 4 and 2
- Dominant language
- C++
- Stars
- 111
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
Using digitalWrite(pin, 0b10) sets the pin high as expected _unless_ it is preceded by a digitalWrite(pin, 0b100), in which case writing 0b10 actually sets the pin low. Subsequent writes (including reattempting to write 0b10) behave as expected.
Recreated in a new blank sketch, using an UNO Wifi R2 and Arduino IDE 2.3.6
```
#define PIN_LED 25 //Wifi R2 built-in LED is on pin 25
void setup() {
//digitalWrite weird behaviour test
pinMode(PIN_LED, OUTPUT);
delay(2000);
digitalWrite(PIN_LED, 0b100);
delay(1000);
digitalWrite(PIN_LED, 0b10); //LED Turns off here; removing the above write causes this write to behave as expected
delay(1000);
digitalWrite(PIN_LED, 0b1);
}
void loop() {
// put your main code here, to run repeatedly:
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the supplied sketch on an UNO Wifi R2 with Arduino IDE 2.3.6, comparing the sequence with and without the preceding digitalWrite(pin, 0b100). Then trace the digitalWrite entry point in the megaavr core and determine why the 0b10 write changes state; done means the reported sequence behaves consistently with the standalone write.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100