HI,
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.
But:
I use my ARD 2650 as an experimental board controlled by an external Delphi program, sending commands to the ARD, that does what it is supposed to do, and giving respons(es) to the calling Delphi program. It means that I don't know how the different ports/registers (DDRx and PORTx) will be configured at runtime / executing the projects.
I don't want to (re)compile the ARD-code whenever I start a new project, so I am searching for a more general routine, that can set the ports ( eg.: DDRx and PORTx) to the project dependent mode.
I intend to use the PINMODE command programming the DDRx - registers (and DIGITALREAD / DIGITALWRITE commands when reading/writing to the ports.)
I konow I can use the command:
DDRx = 0xFF; and DDRx = 0x00; (out / inp )
But it's faster (for me - not necessary programmatic) to use the PINMODE-command.
New project:
PORT A will be OUTPUT and port A will be input:
Set DDRA as OUTPUT:
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.
an alternative could be:
Running the Command PINMODE(N,OM); //N = pinnumber, OM = i/o-Mode from the Delp. prgm 8 time (per port) (an eqivivalent in the ARD-code).
If this is possible it will reduce the code-overhead in the ARD quite significant, thereby speeding it up, and speed is a critical factor.
These "setup - routines " will NOT be in the void setup() section
So the question is:
Is this possible ?
Kris aka snestrup2016