Hi everyone! can someone help me I'm a newbie and a student, I'm having a hard time figuring out the code. thank you very much for answering.
The Servo library that comes with the IDE has an example named Knob that does just that.
ok. I'll check it out. thank you very much. Appreciate it a lot
Sorry, The knob example will control position not speed. I will look into controlling speed.
yeah, that's what I always get I can't find something related to controlling of speed
Hello
Well, I think you need a timer, based on the BLINKWITHOUTDELAY example of the IDE, to generate angle steps per time interval.
There are example codes within the IDE. They are often useful to start from.
What code have You got running so far?
so far. nothing sir, I only have an idea using potentiometer to control the position but not the speed
where can I see that? sorry newbie here, I'm not yet familiar where I can find this and that.
Then start exploring IDE example codes. They are well documented, lots of comments telling what the lines are doing.
Of course You look for any sight of speed thoughts....
Searching forum for servo + speed is another tip.
inside the IDE. Select tab file, example, digital, blinkwithoutdelay
You have to make some mods for your project.
oohh i see. thank you very much
Thank you sir for the tips. Searching for it now. hope to find an answer
That's the "trick". You can slow it down by moving in small-steps. (I don't know if the library allows fractional degrees.) You can't speed it up.
You should probably start by writing some code to move it slowly before trying to control it with a pot.
You could use the MoToServo class of my Mobatools Library. This class has a method to set the speed of the Servo.
Here is a modified example from the varSpeedServo library that changes the speed in accorcance with a potentiometer setting. Pot connected to pin A0, servo to pin 9. Note that the wait function blocks.
#include <VarSpeedServo.h>
// create servo object to control a servo
VarSpeedServo myservo1;
void setup()
{
// initialize serial:
Serial.begin(9600);
myservo1.attach(9);
}
void loop()
{
int LEF = 0;
int RIG = 180;
//int SPEED1 = 160;
int SPEED1 = analogRead(A0) / 4;
myservo1.write(LEF, SPEED1);
myservo1.wait();
SPEED1 = analogRead(A0) / 4;
myservo1.write(RIG, SPEED1);
myservo1.wait();
}
thanks. but when I tried to simulate it in tinkerpad. this one pops out
That means that that library is not included with TinkerCad. So the next thing to look at is the sweep example that comes with the servo library. The delay between steps sets the speed. Vary the delay time with the pot reading. Use the map function to scale the 0 to 1023 from the pot to the range of delay times.
Then learn to use millis() for timing to replace the, blocking, delay function.
Non-blocking timing tutorials:
Several things at a time.
Beginner's guide to millis().
Blink without delay().
Get a real Arduino.
thank you for your help sir. I have download the real Arduino, its such that my professor require us to use TinkerCad
It seems that the forum software ate my previous reply.
So the next thing to look at is the sweep example that comes with the servo library. The delay between steps sets the speed. Vary the delay time with the pot reading. Use the map function to scale the 0 to 1023 from the pot to the range of delay times.
Then learn to use millis() for timing and get rid of delay.
Non-blocking timing tutorials:
Several things at a time.
Beginner's guide to millis().
Blink without delay().