Changes for 2.0.0 preview - analogRead() #524
SpenceKonde
started this conversation in
Development Plans
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The question of "how to refer to analog pins vs channels" has always been a major headache here.....
I finally hit upon a solution I like - the rough patch is that code that passed ADC channels as numbers (without the A) will need to be adapted - numbers need to be wrapped in ADC_CH() macro, converted to the An constants, or manually OR'ed with 0x80.. But these days, everything lets you analogRead() digital pin numbers seamlessly.
I already had made all the #defines that were channel numbers (channel) | 0x80 ... 2.0.0 will take that a step further. analogRead() will expect a digital pin number (which does not have the 0x80 or'ed with it, hence is 127 or less) - or a channel number with the 0x80 or'ed with it. so if the argument passed to analogRead & 0x80, it's a channel number, strip the high bit and use it, otherwise, it's a digital pin number - pass it to digitalPinToAnalogInput() first.
The An constants will be defined by the core so analogRead(A1) will work the same as always, and the other channels that can be read will also be #defined in a similar way; this also makes it reasonably straightforward to expose the differential channels, where present (and this is being done too, defines of the form DIFF_Ap_An_gX will be provided) too.
Beta Was this translation helpful? Give feedback.
All reactions