Hey guys, I have an interesting problem for you, I have got some code here that I need help with:
int Servo1 = 13; // pin for servo
int myAngle;
int pulseWidth1;
void setup() {
pinMode(Servo1, OUTPUT);
}
void loop() {
Servo1Angel(0);
}
void Servo1Angel (int myAngle) {
pulseWidth1 = (myAngle * 11) + 500; // Converts angle to microseconds
digitalWrite(Servo1, HIGH); // Set servo high (turns it on)
delayMicroseconds(pulseWidth1); // Wait a very very small amount
digitalWrite(Servo1, LOW); // Set servo low (turns it off)
delay(20); // Typical Refresh cycle of servo (20 ms)
}
My aim is to make a servo library that works on any arduino pin because I do not like to be limited by PWM pins. So my problem is that , the code works but when ever I add a delay in the loops it obviously affects the other delays in the Servo1Angel therefore affecting the servo square wave I wanted to create, so is there another way ( other that using PWM) to replicate the result of that code and be able to use delays.
As this library is supplied with the Arduino IDE sense version 17, all you have to do to add it to your sketch is to press Sketch/Import library/Servo.
As of Arduino 0017, the Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.
I just counted on my Duemilanove, and there are not 12 PWM pins.
Well first carefully read the links provided and then come back to tell us that the now standard servo library doesn't meet the requirements you originally stated you require. Also Servo and PWM have no connection with each other then both require the use of hardware timers to work and there are only so many timers avalible.
Well maybe I am, I have arduino 16 and I didnt know they upgraded the arduino servo library, I know that servo's dont need PWM, thats why i found it strange that the old servo library could only run on PWM pins so I wanted to create a way to do so, thanks for the help guys... much appreciated