Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analogWrite() uses a threshold when writing to a digital port #706

Open
tedtoal opened this issue Jul 22, 2023 · 0 comments
Open

analogWrite() uses a threshold when writing to a digital port #706

tedtoal opened this issue Jul 22, 2023 · 0 comments

Comments

@tedtoal
Copy link

tedtoal commented Jul 22, 2023

When analogWrite() is called to write to a pin that is in digital mode, it maps the analog output value to 8 bits and then applies a threshold of 128, writing LOW if < 128 else HIGH. To me this is plain wrong, as one expects in C and C++ that only a value of 0 will result in LOW.

I suggest the code be changed as follows:

311,316c311
<   value = mapResolution(value, _writeResolution, 8);
<   if (value < 128) {
<     digitalWrite(pin, LOW);
<   } else {
<     digitalWrite(pin, HIGH);
<   }
---
>   digitalWrite(pin, value == 0 ? LOW : HIGH);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant