How to check (at runtime) how many digital pins the hardware has?

Status
Not open for further replies.

Ben

Well-known member
Is there a way to check if a number is inside the range of availabe(physically existing) digital pins on a board?
I'd like to use it to give interactive feedback on a serial console if a wrong pin number is send to the teensy, i'd like to use a helper function like so:

Code:
int isValidDigitalPin(int pin) {
	if ( (pin >= 0) && (pin <= 33) ) return 1;
	else return 0;
}
while 33 is correct on the Teensy 3.2, i'd rather have my code somewhat platform agnostic or platform-flexible by dynamically setting this upper limit at compile time to be compatible with upcoming T3++.
Is there something #defined to do this?

Ben
 
There's a section in "core_pins.h" that might be helpful:

Code:
#if defined(__MK20DX128__)
#define CORE_NUM_TOTAL_PINS     34
#define CORE_NUM_DIGITAL        34
#define CORE_NUM_INTERRUPT      34
#define CORE_NUM_ANALOG         14
#define CORE_NUM_PWM            10
#elif defined(__MK20DX256__)
#define CORE_NUM_TOTAL_PINS     34
#define CORE_NUM_DIGITAL        34
#define CORE_NUM_INTERRUPT      34
#define CORE_NUM_ANALOG         21
#define CORE_NUM_PWM            12
#elif defined(__MKL26Z64__)
#define CORE_NUM_TOTAL_PINS     27
#define CORE_NUM_DIGITAL        27
#define CORE_NUM_INTERRUPT      18
#define CORE_NUM_ANALOG         13
#define CORE_NUM_PWM            10
#endif
 
Status
Not open for further replies.
Back
Top