I'm on another arbitrary project (using Arduino Starter Kit) I conjured up just to continue practicing the basics.
I've got my project wired up so that 3 successive LED's strike. But after the 3rd I'd like my attached servo motor to move in a desired increment (not the popular sweeping situation).
Right now, the LED's are working great but just the servo...not so much. Here is the code, which may not be very logical at this point after a few hours of tinkering with the code and trying anything I could think of -
Code: Select all
#include <Servo.h>
Servo myServo;
int pos = 0;
int prevPos = pos + 45;
int greenPin = 11;
int redPin = 12;
int bluePin = 13;
void setup(){
myServo.attach(9);
pinMode (greenPin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
digitalWrite (greenPin, HIGH);
digitalWrite (redPin, LOW);
digitalWrite (bluePin, LOW);
delay(250);
digitalWrite (greenPin, HIGH);
digitalWrite (redPin, HIGH);
digitalWrite (bluePin, LOW);
delay(250);
digitalWrite (greenPin, HIGH);
digitalWrite (redPin, HIGH);
digitalWrite (bluePin, HIGH);
delay(250);
digitalWrite (greenPin, LOW);
digitalWrite (redPin, LOW);
digitalWrite (bluePin, LOW);
myServo.write(prevPos + 45);
delay(250);
}