Hello DeuxVis,
we tested the led with resistor too but it made no defference.
The servo signal output is not connected to ground but that is right and the servo works like this.
We found out that the servo signal is not working when the led is on.
We worked around the problem by switching the led on and of in between the servo pulses of the software pwm.
Not a nice solution and we can not adjust the brightness of the led but it works.
We would be still very grateful if somebody tells us why it is a problem to have the led switched on while driving the servo with the software pwm.
New sketch:
int i=0;
int wert = 0;
void setup() {
pinMode(0, OUTPUT); // onboard LED (Model B)
pinMode(1, OUTPUT); // PWM Servo
analogWrite(0,LOW);
digitalWrite(1,LOW);
// Servo in Startposition
for(int startpos = 0; startpos < 400; startpos +=1)
{
digitalWrite(1,HIGH);
delayMicroseconds(1400);
digitalWrite(1,LOW);
delayMicroseconds(1400);
delay(20);
}
}
// loop --------------------------------------------------------------------------------
void loop() {
// 00 - Reset Led
analogWrite (0, 0);
// 01 - read sensor output and filter it
i = analogRead (0);
wert = (1/i)*500;
// 02 - do something if feeler is activated
if (i >= 1020){
// 02c - call servo function
servoFunktion (2400); // drive to max. position
} // Ende if
} // End loop
// Functions ----------------------------------------------------------------------------
// drive servo to given position "servoWert"
void servoFunktion (int servoWert) {
// software pwm
// sweep 1 counter clockwise
for(int pos = 400; pos < servoWert; pos +=30)
{
digitalWrite (1, HIGH);
digitalWrite (0, HIGH); // Led on
digitalWrite (0, LOW); // Led off
delayMicroseconds(pos);
digitalWrite(1,LOW);
digitalWrite (0, HIGH); // Led on
digitalWrite (0, LOW); // Led off
delayMicroseconds(pos);
delay(15);
}
delay (200); // break
// sweep 1 clock wise
for(int pos = servoWert; pos > 400; pos -=30)
{
digitalWrite(1,HIGH);
digitalWrite (0, HIGH); // Led on
digitalWrite (0, LOW); // Led off
delayMicroseconds(pos);
digitalWrite(1,LOW);
digitalWrite (0, HIGH); // Led on
digitalWrite (0, LOW); // Led off
delayMicroseconds(pos);
delay(15);
}
delay (200);
}