#define *name* = 54 doesn't work, but works with byte

Hello everyone,

I’m not very experienced at Arduino. Reading here onthe forums I noticed that using #define instead of defining a byte for pin numbers would save memory, hence why I’m trying to do this.

I’m using an Arduino Mega 2560 for this application.

My application is not supposed to do anything specific yet, except from testing some stepper motors I bought online, through my RAMPS 1.4 driver board.

My question is: Why does my program not compile with following code (?):

#define X_STEP_PIN    = 54;
#define X_DIR_PIN     = 55;
#define X_ENABLE_PIN  = 38;
#define X_LS_LOW      = 3;
#define X_LS_HIGH     = 2;

void setup() {
  pinMode(X_STEP_PIN, OUTPUT);
}

void loop() {

}

When it can compile the following code (?):

byte X_STEP_PIN    = 54;
#define X_DIR_PIN     = 55;
#define X_ENABLE_PIN  = 38;
#define X_LS_LOW      = 3;
#define X_LS_HIGH     = 2;

void setup() {
  pinMode(X_STEP_PIN, OUTPUT);
}

void loop() {

}

Also I would like to know if it is correct to use 54 and 55 as digital inputs when using A0 and A1 as pinMode, INPUT, but I’ll just test this if you guys don’t have an answer for that.

Thanks in advance!

You are not using the proper syntax. No ";" No "="

https://www.arduino.cc/reference/en/language/structure/further-syntax/define/

#define X_STEP_PIN     54
#define X_DIR_PIN      55
#define X_ENABLE_PIN  38
#define X_LS_LOW       3
#define X_LS_HIGH      2

void setup() {
  pinMode(X_STEP_PIN, OUTPUT);
}

void loop() {

}

Thanks a lot! It works now :slight_smile: