How to call a function with Vpin as parameter?

I have to confess that my brain is almost stucked…
Please show me the way to call a function with Virtual Pin number as a parameter?
I mean how to call the function
printTemperature(Probe05,V15);

and how to declare the printTemperature function at the V15 part of declaration ???

What is it you want to achieve? I think I know, but you are probably making a mistake in how to achieve this :slight_smile:

1 Like

@mikekgr if the 2 arguments were both integers it can be as simple as:

 void printTemperature(int Probe05, int V15){
     // do something with the 2 arguments
 } 

or with Strings:

 void somefunction(String one, String two){
    // do something with Strings one and two
}

Dear @Lichtsignaal ,
thanks for your helping hands.
For some reason I get in trouble to pass the virtual pin as a parameter in my calling function.
Shortly I want to have a general type temperature printing function with parameters the temperature probe name {Probe01, Probe02 etc} and the Virtual pin that is used on History Graph widget {V11, V12 etc}.

That is what i am trying to do…

Thanks and Best Regards,
Mike Kranidis

Dear @Costas,
can I referenced blynk virtual pin let’s say V11 as integer?
Is not characters array or something?

Thanks and Best Regards,
Mike Kranidis

Although I don’t like to see virtual pins referenced without the V prefix I believe you can use them without as the others are either gpX, (Digital) or adcX (Analogue).

That said, many months ago when I was working with virtual pins I seem to remember joining a char (V) to and integer (0 to 127) to make VX. This suggests you have to call them as Strings.

Look forward to hearing more from you on this.

@Costas

The bellow sketch is working so you can test it :

/// START of  DS18B20 temperature sensors printing Function printTemperature ///
void printTemperature(DeviceAddress deviceAddress, char Vport)
{

float tempC = sensors.getTempC(deviceAddress);
   if (tempC == -127.00) 
   {
   Serial.print("Error getting temperature  ");
   } 
   else
   {
   Serial.print("°C: ");
   Serial.print(tempC);
   /// Send it to the server and to history widget 
   Blynk.virtualWrite(Vport, tempC);
   }
}
/// END of DS18B20 temperature sensors printing Function printTemperature ///

/// START of DS18B20 temperature sensors process Function reportTemperature() this will be running using simpletimer each ex 5 seconds ///
void reportTemperature()
{
  clockDisplay();
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01,V11); /// Probe01 holds the temperature in C for 1sr DS18B20 temperature sensor ///
  Serial.println();
  
  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02,V12); /// Probe02 holds the temperature in C for 2nd DS18B20 temperature sensor ///
  Serial.println();
  
  Serial.print("Probe 03 temperature is:   ");
  printTemperature(Probe03,V13); /// Probe03 holds the temperature in C for 3rd DS18B20 temperature sensor ///
  Serial.println();
  
  Serial.print("Probe 04 temperature is:   ");
  printTemperature(Probe04,V14); /// Probe04 holds the temperature in C for 4th DS18B20 temperature sensor ///
  Serial.println();

  ///Serial.print("Probe 05 temperature is:   ");
  ///printTemperature(Probe05,V15); /// Probe05 holds the temperature in C for 5th DS18B20 temperature sensor ///
  ///Serial.println();

 }
 /// END of DS18B20 temperature sensors process Function reportTemperature() ///

@Costas

Sorry something wrong in my conclusion above.

The code snippet that I wrote above is working. Somewhere else I had a mistake…

I will update the original post tho …

1 Like

Guys, pins V1, V2, V3 can be referenced as numbers :wink:

2 Likes

Dear @vshymanskyy do you mean as @Costas already posted, to reference ex V1 simple as 1 ?
Yes I tested already and it is working but can you suggested me/us a way to referenced as V1 ? ( for better consistency ) What is the proper declaration type and how to handle it???

Thanks and Best Regards,
Mike Kranidis

Yup guys you can just use ints … 0,1,2,3,4… instead of V0,V1,V2,V3,V4 etc