Now the servo now at pin 10 turns by itself and on the second turn, the servos turn at the same time, but when they were not swapped the servos turned at the same time but than on the second turn the servo that was at pin 9 turned by itself.
I wonder why it is doing this from me swapping the pins that the servos were connected to. What do you think?
Here is the code I used just in case you forgot:
Code: Select all
#include <Servo.h>
#include "Wire.h"
#include "Adafruit_LiquidCrystal.h"
Adafruit_LiquidCrystal lcd(0);
Servo myservo1;
Servo myservo2;
const int knockSensor = A0;
const int threshold = 50;
int health = 500;
int sensorReading = 0;
int pos;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Serial.println("Nerf Target v0.0.1, github.com/mcoms/nerf-target, 2014.");
lcd.begin (20 , 4);
lcd.clear();
Serial.begin(9600);
myservo1.attach(9);
myservo1.write(0);
myservo2.attach(10);
myservo2.write(179);
}
void loop()
{
do
{
myservo1.detach();
myservo2.detach();
sensorReading = analogRead(knockSensor);
lcd.setCursor(0, 1);
Serial.println(health);
lcd.println(health);
if (sensorReading > threshold) {
Serial.println("Knock!");
health = health - sensorReading;
Serial.print(sensorReading);
lcd.print(sensorReading);
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1);
}
} while (health > 1);
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
myservo1.attach(9);
myservo2.attach(10);
delay(15);
myservo1.write(0);
myservo2.write(179);
delay(2000);
myservo1.detach();
myservo2.detach();
delay(6000);
myservo1.attach(9);
myservo2.attach(10);
delay(15);
myservo1.write(179);
myservo2.write(0);
delay(2000);
myservo1.detach();
myservo2.detach();
delay(1000);
health = 500;
}