[SOLVED] BLYNK_READ with argument as a variable on the Particle Photon

I would like to use one BLYNK_READ with dynamic (variable) virtual pin number, i.e., put to the function its argument as a variable. Is it possible please? I have found out in my project with Photons, that the argument (virtual pin) should be a literal, either for instance V1 or 1. If it is a variable, the mobile app widget does not update its value. I would like to use the same code (Particle IDE app) on two Photons but managed with one Blynk project where each Photon uses different virtual pins.

The sample code is as follows:

byte pinVirtual;
void setup() {
    deviceId = System.deviceID();
    if (deviceId.equalsIgnoreCase(photon1Id)) {
        pinVirtual = 1; // or V1
    if (deviceId.equalsIgnoreCase(photon2Id)) {
        pinVirtual  = 2; // or V2
void loop() {;
BLYNK_READ(pinVirtual)   // Does not work with variable
//BLYNK_READ(1)   // Works with numeric literal
//BLYNK_READ(V1)   // Works with string literal
    Blynk.virtualWrite(pinVirtual, data);  // Works in either case

Please, is the argument of BLYNK_READ a regular variable or is it a matter of preprocessor and compilation?

Yes. You can do this.

Thank you. It works and has solved a problem in my project.

Hi there,
it would be nice to see a hole functioning project.

This topic is more than 5 years old, and Blynk has changes significantly during that time.
Also, BLYNK_READ(vPin) is a function which is used infrequently, and as a new user to the forum I guess that you may be using the function in an inappropriate way.

I’d suggest that you start a new topic under the category of “Need help with my project” and provide all of the details that are requested when you do that, including which version of the Blynk app you are using, and the code that you are using. You should also include a description of exactly what it is that you are trying to achieve with your project.