/* Test software to test: * the servo output * DC Motor control * analog input * * */ #include // give it a name: int led = 13; Servo myservo; // create servo object to control a servo int pos = 0; // variable to store the servo position //L293 control for channel A as full H-bridge int enablePin = 2; int in1Pin = 1; int in2Pin = 0; int switchPin = 4; //this is where I forgot the 1k0 pull down int potPin = A1; void setup() { myservo.attach(3); // attaches the servo on pin 3 to the servo object // initialize the digital pin as an output. pinMode(led, OUTPUT); //L293 H-Bridge pinMode(in1Pin, OUTPUT); pinMode(in2Pin, OUTPUT); pinMode(enablePin, OUTPUT); pinMode(switchPin, INPUT); } void loop() { int speed = analogRead(potPin) / 4; boolean reverse = digitalRead(switchPin); //and this is where I would be able to reverse had I remembered the pull down setMotor(speed, reverse); for(pos = 0; pos <= 180; 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 = 180; pos>=0; 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 } digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } void setMotor(int speed, boolean reverse) { analogWrite(enablePin, speed); digitalWrite(in1Pin, ! reverse); digitalWrite(in2Pin, reverse); }