Numeric Input Widget Not In Sync With Gauge Widget

Hi Blynkers,
Small issue here…I have a Numeric Input Widget set to 0.25 steps (0-10 in increments of 0.25) which writes its value to a Gauge Widget which label setting is set at “/pin.##/” so as to display a value with 2 decimal places. The issue is as you change the Numeric Input Widget by the set 0.25 step the Gauge Widget only acknowledges the whole number so it increments at every 4 steps by 1. Can someone please explain why?

{
  CalcSt = param.asInt();
  CycleTime = map(CalcSt, 0, 100, 0, 30000);
  Blynk.virtualWrite(V5, CalcSt);           //Send value to gauge display
}
```![Screenshot_20190515-235941_Blynk|243x500](upload://3DzBN9wegu2cLbBokUQMuyxxCwJ.jpeg) ![Screenshot_20190516-000017_Blynk|243x500](upload://8k7FIKPWRmqoOvhWUewAttXd4N3.jpeg)

You’re choosing to work with the result as an Integer variable type. Integers are whole numbers, hence your problem.

It’s not clear from your code snippet what variable type you’ve declared CalcSt as, but if you declared it as a float variable and used:

CalcSt = param.asFloat();

then it should solve your problem.

Pete.

2 Likes

Brilliant!! Thanks.

1 Like

Still have a slight issue here. The 2 decimal numbers show up now but for some reason the mapping calculation is wrong. Any ideas why ( CalcSt is a float) ie. 1.25 should output 3750, 1.50 should output 4500 and so on

BLYNK_WRITE(V4)   //Numeric Input Widget
{
  CalcSt = param.asFloat();
  CycleTime = map(CalcSt, 0, 10, 0, 30000);
  Blynk.virtualWrite(V5, CalcSt);           //Send value to gauge display
  Serial.print(CalcSt);
  Serial.print(" : " );
  Serial.print ( CycleTime);
  Serial.println();
}
0.75 : 0
0.50 : 0
0.25 : 0
0.00 : 0
0.25 : 0
0.50 : 0
0.75 : 0
1.00 : 3000
1.25 : 3000
1.50 : 3000
1.75 : 3000
2.00 : 6000
2.25 : 6000
2.50 : 6000
2.75 : 6000

2 Likes

I’d forgotten (or probably never realised) exactly how the Map function worked.
The solution is simple though. Multiply your result by 100 and either change your Map parameters or divide by 100 and use your existing Map values.

Pete.

A further issue with this…the mapping function with the math formatting works. But how do I get a value from the BLYNK_WRITE function to a void function? I need a value from CycleTime and then taken to be used in the CycleTime in void FeedPump(), as there is no syntax like Blynk.virtualRead. I have read the Blynk documentation and the example they show does not suit this case

BLYNK_WRITE(V4)   //Numeric Input Widget
{
  CalcSt = (param.asFloat()*100);
  CycleTime = map(CalcSt, 0, 10, 0, 30000);
  Blynk.virtualWrite(V5, (CalcSt/100));           //Send value to gauge display
  Serial.print(CalcSt/100);
  Serial.print(" : " );
 
  Serial.println();
  
  
}

void FeedPump()
{ 
  if (StepPump.check() == 1)
  {
    if (StepState == HIGH)
    {
      StepPump.interval(CycleTime/100);         //On time 0-5000l/h
       Serial.print ( CycleTime/100);
      Blynk.virtualWrite(V7, 255);
      StepState = LOW;
    }
    else
    {
      StepPump.interval(75000);             //Cycle gap 1min 15sec
      Blynk.virtualWrite(V7, 0);
      StepState = HIGH;
    }
  digitalWrite(FeedPin, !StepState);        //Switch stepper pump pin on
  digitalWrite(LedFeed, StepState);         //Switch stepper LED on
  }
}

I’m not 100% sure what you’re trying to do.
The CycleTime variable is global, so available in the void FeedPump function.

Pete.