Defining virtual pins as constants

Quick question: is it possible to define a virtual pin using #define or const so I don’t have to manually change or find and replace all instances of a vpin? I do this for I/O pins to reduce bugs and errors, as having ‘magic numbers’ in code is generally a bad idea.

I tried

#define BUTTON_PIN

and

const uint8_t BUTTON_PIN

but both of these styles made my project stop working. Is there some adjustment I can make or is this not possible with Blynk?

Cheers.

#define vPin1 V1
#define vPin2 V2

Works fine for me and a few other community members.

Wait using just 1? Or 2? Not V1, V2?

@snowman I believe if a pin is not prefixed D for digital or A for analogue then with no prefix it is a virtual pin.

Therefore if you are defining your own pins then you ignore the normal V prefix.

I guess rather than

#define vPin1 1 
#define vPin2 2

you will be wanting to do something like:

#define BedroomSensor 1
#define MainRelay 2
#define TemperatureSensor 3

both “1” and “V1” notation will work.
“V1” is much more preferred

You have to use #define. const int won’t work

OK I tried again today and #define worked just fine. I think my computer was tired last night…

Both ‘1’ and ‘V1’ worked, but on your recommendation I changed to ‘V1’ style.
I see why #define works as a simple text replacement is what’s needed, rather than const int.
Thanks for clarification!