Society of Robots - Robot Forum
Software => Software => Topic started by: SUTO the G on June 09, 2013, 07:19:36 AM
-
here is the code:
#include <Servo.h>
Servo scanner;
int scan_angle = 0; //angle that the scanning servo is at
void setup()
{
scanner.attach(3);
}
void loop()
{
if(scan_angle < 180) //overflow protection
{
scan_angle += 1; //turn right
scanner.write(scan_angle);
delay(15);
}
else
{
scan_angle = 0;
scanner.write(scan_angle);
delay(15);
}
}
I don`t understand why does my motor make smaller angular turns if I put delay(5). I am trying to make it to scan from 0 to 180 deg and when it reaches 180 to jump back to 0, but I want to make this as fast as possible. If I change the delay(15) to delay(5) it goes faster but it doesn`t seams to go to 180 deg only to 90. Why is this happening? What can I do to make it go to 180 deg fast. Someone please help me!
-
where's the delete key? lol :o
-
5 milliseconds between pulses may be too small, and the servo doesn't like it when there's not enough pause between each pulse.
If you want it to turn faster, try adding 2 instead of 1 for each iteration through the loop.