#include <Servo.h>
Servo helmet1;
Servo faceplate1;
Servo helmet2;
Servo faceplate2;
int val; // variable for reading the pin status
int val2; // variable for reading the delayed/debounced status
int buttonState;
int servostatus = 0;
int switchPin =2; // Switch connected to digital pin 2
int ledPin = 5;
void setup() // run once, when the sketch starts
{
//servo 1
helmet1.attach(9);
faceplate1.attach(10);
helmet2.attach(3);
faceplate2.attach(6);
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
buttonState = digitalRead(switchPin);
helmet1.write(0);
faceplate1.write(175);
helmet2.write(0);
faceplate2.write(175);
}
void loop() // run over and over again
{
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!
helmet1.write(0);
faceplate1.write(0);
helmet2.write(180);
faceplate2.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);
helmet1.write(120);
faceplate1.write(110);
helmet2.write(50);
faceplate2.write(0);
}
}
}
buttonState = val; // save the new state in our variable
}
}