Declaring a variable globally but getting "not declared in this scope"

I have a code I’ve been working on for awhile. Up until Monday, it would verify and upload to my controller without issue. I added a few void commands, but that shouldn’t be affecting my global variable declaration. When I try to denote relayPin0 as the variable “D0” I keep getting an error message that D0 is not declared in this scope. Any thoughts on what could be causing this?

JGD-final.ino (23.7 KB)

hi!

If you talk about this:

const int relayPin0 = D0;

it’s normal

this must be like this:

const int relayPin0 = 0;

“D0” is not a integer (int) and Pin Numbers are Integer

But…your code is very, very long, difficult to read, you can reduce it considerably, you duplicate too much thing unnecessarily.

it is possible to pass arguments to functions and thus to make “generic” functions instead of muktipliers for each case.

an example, all your functions "void Y3Off (), void X6Off (); etc … can use a single common function.

for (int i = 0; i < 10; i++) { Y_Off(i) }

void Y_Off(int Id) {
Serial.print(“Switch Y”);
Serial.print(id);
Serial.println(" turn off …");
}

you can do the same for the functions (and in many others) “void Y3On (), void X6OOn ()” by adapting the parameters

Vous pourrez réduire la longeur de votre code d’au moins 70% :slight_smile:

You will gain enormously in resources and speed, and especially in managing your code

Did you change the board you have selected from the Tools > Board menu? Only some of the ESP8266 boards define pin numbers using the Dn pin numbers. For example, the "LOLIN(WEMOS) D1 R2 & mini" board does:

static const uint8_t D0   = 16;
static const uint8_t D1   = 5;
static const uint8_t D2   = 4;
static const uint8_t D3   = 0;
static const uint8_t D4   = 2;
static const uint8_t D5   = 14;
static const uint8_t D6   = 12;
static const uint8_t D7   = 13;
static const uint8_t D8   = 15;
static const uint8_t RX   = 3;
static const uint8_t TX   = 1;

but the "Adafruit Feather HUZZAH ESP8266" board does not:

The reason for this is that some manufacturers decided to label the pins on their boards (e.g. WeMos D1 Mini) with arbitrary numbers, and so a mapping between those numbers and the ESP8266 GPIO pin numbers used internally by the ESP8266 core for Arduino is required. That was accomplished by adding these Dn definitions in the variant files used by those boards. Other manufacturers labeled their boards with the actual GPIO numbers of each pin, and so no Dn notations were required. I suppose it might have made sense to add dummy definitions to those variants for the sake of intercompatibility:

static const uint8_t D1   = 1;

etc.