westfw:
I wonder how long we'll have Arduino Libraries doing "things" in the pre-Arduino-1.0 ways
Until someone gets around to changing? ![]()
westfw:
I wonder how long we'll have Arduino Libraries doing "things" in the pre-Arduino-1.0 ways
Until someone gets around to changing? ![]()
The problem for library or example authors is that while
pinMode(pin, INPUT_PULLUP);
is much better/clearer than
pinMode(pin, INPUT);
digitalWrite(pin, HIGH)
it's not so much better than
#if (ARDUINO >= 100)
pinMode(pin, INPUT_PULLUP);
#else
pinMode(pin, INPUT);
digitalWrite(pin, HIGH);
#endif
Code with a lot of #if clauses in it is really awful to read ![]()
void RunningLights(byte red, byte green, byte blue, int SpeedDelay) {
int Position=0;
for(int i = 0; i < LED_TOTAL; i++) // when did this change from "j" to "i" ? <<==========
{
Position++; // Position + Rate;
for(int i = 0; i < LED_TOTAL; i++) {
Whoops... That was from changing stuff up and not correctly rewriting the previous code
westfw:
Meh. I'm with TomGeorge. "pinMode(pin, INPUT_PULLUP)" is clear, obvious, and portable to any device that implements internal pullups in some way (perhaps with a bit of effort.)
Right, what's the value added of using some device-specific code just to set the pin to input mode and turn on the pullup? How many times are you going to do that in a program? Who cares how long THAT takes?
(Did you know that the SAMD chips have an entirely different way to enable pullups, but go to significant expense inside digitalWrite() to duplicate the AVR behavior? That's one of the reasons that digitalWrite() on the Zero isn't 3x faster than Uno's digitalWrite(), despite the 3x higher clock rate. Grr.)
I'm more familiar with the freescale chips used in the Teensy family. They have some blindingly fast, device family-specific methods for digital I/O -- if you need it. The direct I/O techniques in the encoder and OneWire libraries come to mind. I assume the SAMD chips have similar device-specific facilities. But, again, if you don't need the speed, go with something easy to understand and portable.
Hi,
gfvalvo:
Right, what's the value added of using some device-specific code just to set the pin to input mode and turn on the pullup? How many times are you going to do that in a program? Who cares how long THAT takes?
It makes code easier to read and debug for all the Arduino observers who DIDN'T write the 100s of lines of code.
Get the code working, then think about speeding things up.
If you need to change platform, INPUT_PULLUP stands out like a dogs b*^$s to anyone experienced in rewriting code.
If you are rewriting for another device, then you will know if that is compatible or not, if not you change it, that is what programmers do.
Tom.. ![]()
TomGeorge:
Hi,It makes code easier to read and debug for all the Arduino observers who DIDN'T write the 100s of lines of code.
Get the code working, then think about speeding things up.
If you need to change platform, INPUT_PULLUP stands out like a dogs b*^$s to anyone experienced in rewriting code.
If you are rewriting for another device, then you will know if that is compatible or not, if not you change it, that is what programmers do.
Tom..
@TomGeorge, I think you misunderstood my comment. My meaning was: "what's the value added of using device-specific code (i.e. direct AVR register manipulation) when there's a general (multi-platform) method available that meets your needs?" And, this is especially true for something like setting the pin mode which will probably be done only once in the program (i.e. speed not important at all).
So, I think I was agreeing with you.