I want to define I/O pins depending on the model I define at the start.
let's consider I define model as A
#define MODEL "A"
then I want my input pins to be
#define IN1 12
#define IN1 14
#define IN1 16
And if I define model as B then I want to define pins differently. How can I do it?
I tried using #ifdef or #if but not sure how to use it properly. Any help is appreciated.
Your post was MOVED to it's current location as it is more suitable.
Could you also take a few moments to Learn How To Use The Forum .
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.
Take a look at #ifdef by means of which you can check whether something is #defined and then conditionally #define more values
At its most basic, but there is much more that you can do
#define typeA
#ifdef typeA
#define X 123
#endif
#ifdef typeB
#define X 456
#endif
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println(X);
}
void loop()
{
}
The preprocessor understands if too, I've seen this over and over.
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
//#define model_A
#define model_B
#ifdef model_A
#define IN1 12
#define IN2 14
#define IN3 16
#endif
#ifdef model_B
#define IN1 2
#define IN2 4
#define IN3 6
#endif
void setup()
{
Serial.begin(115200);
Serial.print("pin definitions IN1 ");
Serial.print(IN1);
Serial.print(" IN2 ");
Serial.print(IN2);
Serial.print(" IN3 ");
Serial.println(IN3);
}
void loop()
{
}
Bob beat me to it but this is a bit different.
Thank you for the reply. Problem is solved.
system
Closed
September 20, 2021, 6:18pm
#7
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.