I am trying to make 2 servo motors move opposite direction because they will be facing each other.
I ran this code that was worked.
But than all the sudden the other servo WAS NOT MOVING.
The only changes of the code that I did before this incident was that I changed the "delay(2000)" for both servos to "delay(1000)"
I commented on the changes in this code:
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);//was 2000
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
myservo1.attach(9);
myservo2.attach(10);
delay(15);
myservo1.write(0);//was 0
myservo2.write(179);//was 179
delay(2000); //before my servo stopped I changed this to 1000
myservo1.detach();
myservo2.detach();
delay(6000);
myservo1.attach(9);
myservo2.attach(10);
delay(15);
myservo1.write(179);
myservo2.write(0);
delay(2000); //before my servo stopped I changed this to 1000
myservo1.detach();
myservo2.detach();
delay(1000);
health = 500;
}
Do you know if this change could have caused the problem?
How do I fix this?