[Solved] Servo Control from slider

Good morning

I am trying now a simple servo control from the dashboard with a slider…
The servo motor reacts on the slider changes, but the slider doesn’t stay in place where I want it to be…it always returns to zero…

Even when moving the slider, 0 values are sent down to the device…this is how the sent data looks like when moving the slider:

54
0
57
0
60
0
68
0
69
0

The code is the same as in the Arduino library servo example…

Is there something missing or must I return a value to the thing function?

thanks in advance
richard

PS: Probably this post will be marked soon as well as spam as all the others…

Hmm…I think what the problem might be…

In the example there is no code that handles events with empty data…

Hello Richard,

You’re right, but it is easily solved by including the instruction “is_empty()” as in the code below:

thing["position"]<<[](pson &in){
     if(in.is_empty()){
        in = aux_position;
     }else{
       new_position = in;
       aux_position= (int)new_position;   
     }
 };  

Where new_position is a global integer and aux_position is a global Pson defined at the beginning of the code, iniciallized with an standard value.

Hope it helps other people ¿How did you solve it?

Hi Jorge

I did a similar thing…discovered it while I was playing with the linux client to test before going the openwrt way (o;

thing["servopos"] << [](pson& in){
    if(in.is_empty())
      in = (int)servopos;
    else
    {
      servopos = (int)in;
      servo1.write((int)in);
    }
    servopos = in;
};

cheers
richard

1 Like