snestrup2016:
According to : Is it legal to use pinMode() inside void loop()? - Programming Questions - Arduino Forum programming pinmode (xx,ZZ) in a loop in not a smart idea.
No, you read it wrong. Unnecesarily calling pinMode() (note C++ is case sensitive, please use the correct case in your function names) over and over again in a loop is not a smart idea. For example this is silly:
void setup() {}
void loop() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
because since the pin is only ever used as an output and you know it will be used as such from the beginning you can just call pinMode() once in setup():
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
snestrup2016:
for (int n = 22; n = 29; ++n)
{
PINMODE(n,1);
}(pin 22 --> pin 29 is portA[0] --> portA[7] )
and
Set DDRB as OUTPUT:
for (int n = 10; n = 13; ++n)
{
PINMODE(n,0);
}
for (int n = 19; n = 23; ++n)
{
PINMODE(n,0);
}These commands will be only RUN ONCE per project.
That's perfectly fine. But note that the Arduino standard API function name is pinMode(), not PINMODE().
snestrup2016:
speed is a critical factor.
Well you should know that the Arduino I/O functions are not very efficient. They are intended to be beginner friendly and portable but are typically much slower than writing directly to the registers.
snestrup2016:
These "setup - routines " will NOT be in the void setup() section
That doesn't matter.