-
-
Notifications
You must be signed in to change notification settings - Fork 88
define digitalPinHasPWM for UNOWIFIR4 & MINIMA #287
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually there is no need to add such define because the same result can be achieved with something that is already defined in the Arduino core.
IS_PIN_PWM(getPinCfgs(p, PIN_CFG_REQ_PWM)[0])
where p
is the pin number (D0, D1... and so on).
So that a general macro (to be more readable) can be written as
#define digitalPinHasPWM(p) (IS_PIN_PWM(getPinCfgs(p, PIN_CFG_REQ_PWM)[0]))
This approach is more generic because uses core functions already available, however has some drawbacks: it does not lie.
The pin marked with ~ on the Arduino board are not in fact the only pin with PWM capability but the pin that have guarantee independent PWM .
Almost all available pin on Uno have PWM capability however some share the same timer and so are not completely independent
- D0 and D1 shares the same timer
- D2 and D3~ shares the same timer
- D4 and D5~ shares the same timer
- D6~ and D7 shares the same timer
- D8 and D9~ shares the same timer
- D10~ and D13 shares the same timer
- D11~ and D12 shares the same timer
My main point is about defining the macro to make old sketches for R3 compile. |
Defining digitalPinHasPWM will make that those sketches using it from older boards, like UNO R3 or Nano, can also be used with UNO R4, without extra complications for non advanced users (like me).