I’ve thought about this for a long time and mostly just gone on with it, until today when it began to nag at me for an answer…
int port1 = D0;
pinMode(port1, OUTPUT);
etc…
why do we set the type to int when D0 doesn’t seem to be an int?
I’ve thought about this for a long time and mostly just gone on with it, until today when it began to nag at me for an answer…
int port1 = D0;
pinMode(port1, OUTPUT);
etc…
why do we set the type to int when D0 doesn’t seem to be an int?
Because they are int’s?
If you check out the source code, you can see them defined just here:
The compiler will convert the 0, 1, 2 (and so on) to int’s when the firmware is built.
It’s a good question. The prototype for pinMode, digitalWrite, etc. specifies it as a uint16_t.
I always assumed storing it in an int was an Arduino thing, but it’s uint8_t in the real Arduino.h.
But it kind of doesn’t matter as all uint16_t values fit in an int, and uint16_t values are padded out to 4 bytes (except in arrays and two adjacent 16-bit quantities in a struct) on the STM32 so both use the same amount of RAM or stack as an int.
Thanks!
Great answers, I figured it was something like that, but didn’t know where to look!
I’ll be able to sleep tonight…
David G.