I just got to play around with Arduino lately so I'm really new on this stuff and sorry for the grammar error.
I got a work where I need to turn the LED on all the time, my plan is to add a slow fade in and fade out later but the problem occurs when I add the servo.
Everytime servo starts moving slowly or fast the LED kinda flickering/dim like it lost power and come back to normal after the servo stops moving.
Here's the scheme I used and the code, I only change some delay to 5ms and so to test it out but no matter what the led is keep flickering.
Im using nano v.3 clone if its matter.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 100; // variable to store the servo position
int ledpin3 = 3;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(ledpin3, OUTPUT);
}
void loop() {
digitalWrite(ledpin3, HIGH);
delay(1000);
for (pos = 99; pos <= 150; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 150; pos >= 30; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 30; pos <= 99; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}