Page 1 of 1

Decision with floating variable

Posted: Wed Jan 12, 2022 10:29 am
by dagr99
I am setting up an Automatic dispenser in flowcode, it has a servo and an ultrasound, I am using the ultrasound of the program that has the GetDistance macro, So I start the components with their macros, enable the servo to the channel, and create a loop, put the GetDistance macro and save to a floating variable called "D" then create a decision for To move the servo, in this I put "D <= 10" since the GetDistance followed the description of the macro call it gives it in cm, I compare it with a value, so that based on that, it activates the servo or not, the problem It comes, that when testing, the servo moves by itself even though the decision is not fulfilled, the sensor is working, it is sending the signal back and forth, but I think the problem is in the formulation of the Decision next to the floating variable, is there a way to write this decision next to floats that I don't know? Should I transform this variable first and then compare it in a decision? Many thanks

Re: Decision with floating variable

Posted: Wed Jan 12, 2022 10:55 am
by medelec35
Hi.
Can you post your project file (.fcfx extension), so we can have a look for you?

Re: Decision with floating variable

Posted: Wed Jan 12, 2022 10:57 am
by mnf
Hi dagr.

Please could you post your code-- someone will be able to help you then...

Martin

Re: Decision with floating variable

Posted: Wed Jan 12, 2022 4:43 pm
by Benj
Hello,

If the variable D is a float then you might want to make your comparison value a float as well.

D <= 10.0

Re: Decision with floating variable

Posted: Tue Jan 18, 2022 11:22 pm
by chipfryer27
Hi

Alternatively, you may wish to consider using an Ultrasonic module that can be preset with a distance. If anything appears within the selected distance then the output toggles Low / High or vice versa. The module does the thinking for you and provides a clear high / low upon detection. Available from all the usual suspects.

How are you controlling the servo? I admit I'm no expert in such but I've seen "budget" controllers act quite weird. Cheap components drifting etc.

Regards