zombienoms
Active Member
Found a tutorial on here by 7sinzz for an automated iron man helmet faceplate as found here
http://www.therpf.com/f24/iron-man-motorised-faceplate-electronics-tutorial-170853/
I got the materials listed and the only thing that I've done differently is use a prewired LED instead of a separate resistor and LED, and instead of using a button switch I want to use a rocker switch. Other than that I followed the directions given by 7sinzz and input the following code in order to get the flicker fade on effect in the leds which is as follows
#include <Servo.h>
//servo 1
Servo myservo;
Servo myservo1;
int val; // variable for reading the pin status
int val2; // variable for reading the delayed/debounced status
int buttonState;
int pos = 0;
int pos1 = 180;
int servostatus = 0;
int switchPin =2; // Switch connected to digital pin 2
int ledPin = 5;
int ledPin2 = 18;
void setup() // run once, when the sketch starts
{
//servo 1
myservo.attach(9);
myservo1.attach(10);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
buttonState = digitalRead(switchPin);
myservo.write(0);
myservo1.write(175);
pinMode(ledPin2, OUTPUT);
}
void loop() // run over and over again
//servo 1
{
val = digitalRead(switchPin); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val2 = digitalRead(switchPin); // read the input again to check for bounces
if (val == val2) { // make sure we got 2 consistant readings!
if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (servostatus == 0) { // is the light off?
servostatus = 1; // turn light on!
myservo.write(0);
myservo1.write(180);
delay(1000);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);
// fading
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
delay(30);
}
} else {
servostatus = 0; // turn light off!
digitalWrite(ledPin, LOW);
delay(15);
digitalWrite(ledPin2, LOW);
myservo.write(180);
myservo1.write(0);
}
}
}
buttonState = val; // save the new state in our variable
}
}
So my issue is I plug things in upload the code but instead of working with the switch or not working at all the LED and the Servos just go on their own accord with no seeming pattern, rhyme, or reason.
I'm electronics illiterate and I'm simply following directions. What am I doing wrong and can someone please help!
My desired outcome is to have about 8-10 LEDs and the 2 servos set up so I flick the switch and the helmet shuts and does the flicker fade on, then flick the switch back and it opens lights shut off, as in the youtube video on the other thread.
Attached photos are of my set up for the board any further information needed just ask I'll provide photos or info to help this along
http://www.therpf.com/f24/iron-man-motorised-faceplate-electronics-tutorial-170853/
I got the materials listed and the only thing that I've done differently is use a prewired LED instead of a separate resistor and LED, and instead of using a button switch I want to use a rocker switch. Other than that I followed the directions given by 7sinzz and input the following code in order to get the flicker fade on effect in the leds which is as follows
#include <Servo.h>
//servo 1
Servo myservo;
Servo myservo1;
int val; // variable for reading the pin status
int val2; // variable for reading the delayed/debounced status
int buttonState;
int pos = 0;
int pos1 = 180;
int servostatus = 0;
int switchPin =2; // Switch connected to digital pin 2
int ledPin = 5;
int ledPin2 = 18;
void setup() // run once, when the sketch starts
{
//servo 1
myservo.attach(9);
myservo1.attach(10);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
buttonState = digitalRead(switchPin);
myservo.write(0);
myservo1.write(175);
pinMode(ledPin2, OUTPUT);
}
void loop() // run over and over again
//servo 1
{
val = digitalRead(switchPin); // read input value and store it in val
delay(10); // 10 milliseconds is a good amount of time
val2 = digitalRead(switchPin); // read the input again to check for bounces
if (val == val2) { // make sure we got 2 consistant readings!
if (val != buttonState) { // the button state has changed!
if (val == LOW) { // check if the button is pressed
if (servostatus == 0) { // is the light off?
servostatus = 1; // turn light on!
myservo.write(0);
myservo1.write(180);
delay(1000);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);
digitalWrite(ledPin, HIGH);
delay(50);
digitalWrite(ledPin, LOW);
delay(00);
// fading
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
delay(30);
}
} else {
servostatus = 0; // turn light off!
digitalWrite(ledPin, LOW);
delay(15);
digitalWrite(ledPin2, LOW);
myservo.write(180);
myservo1.write(0);
}
}
}
buttonState = val; // save the new state in our variable
}
}
So my issue is I plug things in upload the code but instead of working with the switch or not working at all the LED and the Servos just go on their own accord with no seeming pattern, rhyme, or reason.
I'm electronics illiterate and I'm simply following directions. What am I doing wrong and can someone please help!
My desired outcome is to have about 8-10 LEDs and the 2 servos set up so I flick the switch and the helmet shuts and does the flicker fade on, then flick the switch back and it opens lights shut off, as in the youtube video on the other thread.
Attached photos are of my set up for the board any further information needed just ask I'll provide photos or info to help this along