ShitBag
New Member
So recently I took it upon me to build MoeSizzllac's Iron man Mk VII helmet. I have the board loaded with his code, and the servos work with it.
The problem I am having is the board constantly tells the servo's to move back and forth for a few seconds, and then stops. I can make
out what the code means, but I honestly have no clue to what to change to get it to stop. Much appreciation to everyone and all! Here is the code he wrote for it. Dude is amazing for labeling his lines, that helps a bunch.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
int inPin = 6; // the number of the input pin
int outPin =3; // the number of the output pin for the LEDS
int outPin2 =4; // the number of the output pin for the LEDS
int state; // the current state of the output pin
int reading; // the current reading from the input pin
int pos = 0; // variable to store the servo positions
int pos2 = 0; // variable to store the servo positions
// the follow variables are long's because the time, measured in miliseconds,will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 50; // the debounce time, increase if the output flickers
//the two lines above are not really used in my code anymore
void setup() {
pinMode(outPin, OUTPUT); // Make Pin 3 (D3) an Output
pinMode(outPin2, OUTPUT); // Make Pin 4 (D4) an Output
pinMode(inPin, INPUT); // Make Pin 6 (D6) an input
}
void openfaceplate() {
myservo.attach(11); // attaches the servo on pin 11 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo ob
for (pos = 170; pos >= 0; pos -= 10)// goes from 180 degrees to 0 degrees in steps of 10 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
for(pos2 = 0; pos2 <= 170; pos2 += 10) // goes from 0 degrees to 180 degrees in steps of 10 degrees
myservo2.write(pos2); // tell servo to go to position 'pos'
delay(350);
}
void closefaceplate() {
myservo.attach(11); // attaches the servo on pin 11 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo ob
for(pos = 0; pos <= 170; pos += 10) // goes from 0 degrees to 180 degrees in steps of 10 degrees
myservo.write(pos); // tell servo to go to position 'pos'
for (pos2 = 170; pos2 >= 0; pos2 -= 10)// goes from 180 degrees to 0 degrees in steps of 10 degrees
myservo2.write(pos2); // tell servo to go to position 'pos
delay(350);
}
void lightson(){
digitalWrite(3, HIGH); // Set D3 High
digitalWrite(4, HIGH); // Set D4 High
}
void lightsoff(){
digitalWrite(3, LOW); // Set D3 Low
digitalWrite(4, LOW); // Set D4 Low
}
void loop ()
{
reading = digitalRead(inPin);
state = digitalRead(outPin);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && state == LOW) {
delay(15); // software debounce
if (reading == HIGH && state == LOW) {
closefaceplate();
delay(10);
lightson();
}
}
if (reading == HIGH && state == HIGH) {
delay(15); // software debounce
if (reading == HIGH && state == HIGH) {
lightsoff();
delay(10);
openfaceplate();
}
}
}
The problem I am having is the board constantly tells the servo's to move back and forth for a few seconds, and then stops. I can make
out what the code means, but I honestly have no clue to what to change to get it to stop. Much appreciation to everyone and all! Here is the code he wrote for it. Dude is amazing for labeling his lines, that helps a bunch.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
Servo myservo2; // create servo object to control a servo
int inPin = 6; // the number of the input pin
int outPin =3; // the number of the output pin for the LEDS
int outPin2 =4; // the number of the output pin for the LEDS
int state; // the current state of the output pin
int reading; // the current reading from the input pin
int pos = 0; // variable to store the servo positions
int pos2 = 0; // variable to store the servo positions
// the follow variables are long's because the time, measured in miliseconds,will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 50; // the debounce time, increase if the output flickers
//the two lines above are not really used in my code anymore
void setup() {
pinMode(outPin, OUTPUT); // Make Pin 3 (D3) an Output
pinMode(outPin2, OUTPUT); // Make Pin 4 (D4) an Output
pinMode(inPin, INPUT); // Make Pin 6 (D6) an input
}
void openfaceplate() {
myservo.attach(11); // attaches the servo on pin 11 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo ob
for (pos = 170; pos >= 0; pos -= 10)// goes from 180 degrees to 0 degrees in steps of 10 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
for(pos2 = 0; pos2 <= 170; pos2 += 10) // goes from 0 degrees to 180 degrees in steps of 10 degrees
myservo2.write(pos2); // tell servo to go to position 'pos'
delay(350);
}
void closefaceplate() {
myservo.attach(11); // attaches the servo on pin 11 to the servo object
myservo2.attach(10); // attaches the servo on pin 10 to the servo ob
for(pos = 0; pos <= 170; pos += 10) // goes from 0 degrees to 180 degrees in steps of 10 degrees
myservo.write(pos); // tell servo to go to position 'pos'
for (pos2 = 170; pos2 >= 0; pos2 -= 10)// goes from 180 degrees to 0 degrees in steps of 10 degrees
myservo2.write(pos2); // tell servo to go to position 'pos
delay(350);
}
void lightson(){
digitalWrite(3, HIGH); // Set D3 High
digitalWrite(4, HIGH); // Set D4 High
}
void lightsoff(){
digitalWrite(3, LOW); // Set D3 Low
digitalWrite(4, LOW); // Set D4 Low
}
void loop ()
{
reading = digitalRead(inPin);
state = digitalRead(outPin);
// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && state == LOW) {
delay(15); // software debounce
if (reading == HIGH && state == LOW) {
closefaceplate();
delay(10);
lightson();
}
}
if (reading == HIGH && state == HIGH) {
delay(15); // software debounce
if (reading == HIGH && state == HIGH) {
lightsoff();
delay(10);
openfaceplate();
}
}
}