I notice problems with my output pins when I use this method of setting their pinMode:
int allOutputPins[] = {3, 4, 9, 10, 5, A3, 11, 12, 7, 8, A1, A2};
for(int a = 0; a < sizeof(allOutputPins); a++){
pinMode(allOutputPins[a], OUTPUT);
}//end for
Am I doing something wrong?
sizeof allOutputPins / sizeof allOutputPins[0]instead. This idiom is more robust because it works independently of the type of the array. I would use it even if I changeallOutputPinsbase type touint8_t. – Edgar Bonet Sep 05 '15 at 06:07#define countof(a) (sizeof(a)/sizeof(a[0]))in mylocal.hfile (personal file of common idioms). – JRobert Sep 05 '15 at 11:30countofdefine like this:for(int a = 0; a < countof(allOutputPins); a++){– Nick Gammon Sep 05 '15 at 21:28#include <local.h>in your sketch (the Arduino IDE won't know to do it for you); thereafter you can use it anywhere in your sketch, such as how @NickGammon just described. – JRobert Sep 05 '15 at 22:16