AdrianB
Newbie level 1
- Joined
- Mar 19, 2013
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,293
Hi there!
I'm working on a home-made pingpong trainer. The last thing I need is to control my servomotor in that way that it can rotate 90° back and forth several times. Being completely new to electronics, I had no idea where to start. I've gathered information and the needed stuff.
My servomotor is a TowerPro MG995, my microcontroller is a PicKit2 , and I'm wanting to write a code in MPLab v.8.90 to control it. I've been looking around the internet for information, and I've written a first shot (see below).
First of all, would this code work, or is there something wrong in it (apologies for eventual stupid errors) ?
Second: I've written 20ms in the delay() function because I read a servo needs an impuls every 20ms, is this right ? Could someone eventually explain why ?
If there is a better or more efficient way to go, please tell me your knowledge !
Any help will be much appreciated !
Regards,
Adrian
The "servo.h" library is a free library I found on Arduino, including the functions I use here. "servo301" is the name I wanted to give it.
(https://code.google.com/p/arduino/source/browse/trunk/libraries/Servo/Servo.h?r=1088 )
I'm working on a home-made pingpong trainer. The last thing I need is to control my servomotor in that way that it can rotate 90° back and forth several times. Being completely new to electronics, I had no idea where to start. I've gathered information and the needed stuff.
My servomotor is a TowerPro MG995, my microcontroller is a PicKit2 , and I'm wanting to write a code in MPLab v.8.90 to control it. I've been looking around the internet for information, and I've written a first shot (see below).
First of all, would this code work, or is there something wrong in it (apologies for eventual stupid errors) ?
Second: I've written 20ms in the delay() function because I read a servo needs an impuls every 20ms, is this right ? Could someone eventually explain why ?
If there is a better or more efficient way to go, please tell me your knowledge !
Any help will be much appreciated !
Regards,
Adrian
The "servo.h" library is a free library I found on Arduino, including the functions I use here. "servo301" is the name I wanted to give it.
(https://code.google.com/p/arduino/source/browse/trunk/libraries/Servo/Servo.h?r=1088 )
Code:
// Besturingscode servomotor.
#include "servo.h"
Servo servo301;
int pos = 0;
void setup()
{
servo301.attach(7);
}
void loop()
{
for(pos = 0; pos < 90; pos += 1)
{
servo301.write(pos);
delay(20);
}
for(pos = 90; pos>=1; pos-=1)
{
servo301.write(pos);
delay(20);
}
}