How to get number of available pins in code?
It is quite easy actually:

Serial.print("number of digital pins: ");
Serial.println(NUM_DIGITAL_PINS);
Serial.print("number of analog inputs: ");
Serial.println(NUM_ANALOG_INPUTS);


Note that these are compile-time constants defined as macros in a file
named pins_arduino.h. There is one such file for every board supported
by the Arduino environment. Just to take Curt J. Sampson's example, if
someone “made a board with an MCU with 100 digital IO pins available,
yet if only ten of these are brought out to pins on the board”, then the
macros would tell you you have 10 digital pins. Assuming of course that
you installed the proper support package for that particular board.