Go Down

Topic: Servo Randomizer with ease problems... (Read 282 times) previous topic - next topic

gumby

Hello everyone.

 I am very new to programming and I am doing my best here, so forgive me if this is sub-standard work. Here is my issue. I am trying to set a random value for a servo, then use an ease function to chase the random value with the servo position. When the servo position value is reached, set a new random position, and lather, rinse, repeat. I have tried about four thousand variations of this and keep getting the serial port reporting lots of zeros. Does anyone see what I am doing wrong? I suspect that I will need to eventually define a zone as being close enough to the number to be seen as that number so the division doesn't go on infinitely, but I would be happy right now seeing some of the values change as they get closer to the servo position asked for by the random number.

 Here is the code.
Code: [Select]
#include <Servo.h>


Servo servo1;
float spd = 2;
float ran = random(0,180);
float ease;
float current;
float noopos;


void setup()
{
servo1.attach(2);
Serial.begin(9600);
}

void loop()
{
if (servo1.read() != ran)
{
 ease=(ran/spd);
 current = servo1.read();
 noopos = (ease - current);
 servo1.write(noopos);
 delay(10);
}

else
{
   ran = random(0,180);
}
}


 Hopefully someone will have some insight. I tried using the delay function to reduce the speed of the servo, but it was choppy and ugly, so I am hoping this is a better way to get the results I am looking for. Thanks in advance for any information/insight on this problem.

 Peace,

 Gumby

Go Up