RFID Controlled Servo Question for Iron Man Helmet

Hi Everyone,

This is my first time posting on the forum, and I'm relatively new to using arduinos. This year for Halloween I'm modifying my Iron Man helmet to be wireless. I've been using this wonderful tutorial on instructable created by Honus to try and accomplish that: http://www.instructables.com/id/Animatronic-Iron-Man-Mk-III-suit/ . I've manage to make the wireless set up by having the rfid reader in my hand reading the tags which would be located at my finger tips. The signal would be sent through the xbee to another xbee located at my helmet. With the current code for the helmet, the helmet opens for 4 seconds, then closes again after you swipe the tag. This is the code:

#include "Servo.h" // include the servo library

Servo faceplateServo;
Servo chinServo;

int ledPin1 = 4; // control pin for LED eyes
int servoPin1 = 2; // control pin for face plate servo
int servoPin2 = 3; // control pin for chin

void setup() {

faceplateServo.attach(servoPin1); // attaches the servo on pin 2 to the servo object
chinServo.attach(servoPin2); // attaches the servo on pin 3 to the servo object
faceplateServo.write(30); // rotate face plate servo to 30 degrees
chinServo.write(95); // rotate chin servo to 95 degrees
pinMode(ledPin1, OUTPUT); // sets the LED pin as output
digitalWrite(ledPin1, HIGH); // turn on LED eyes

Serial.begin(9600);
}

void loop() {


// look for a capital A over the serial port and turn off LED
if (Serial.available() > 0) {
if (Serial.read() == 'A') { // reads tag over XBee
digitalWrite(ledPin1, LOW); // turn off LED eyes
delay(500); // wait half a second
faceplateServo.write(95); // rotate the face plate servo to 95 degrees
chinServo.write(20); // rotate the chin servo to 20 degrees
delay(4000); // wait 4 seconds
chinServo.write(95); // rotate the chin servo to 95 degrees
faceplateServo.write(30); // rotate the face plate servo to 30 degrees
digitalWrite(ledPin1, HIGH); // turn on LED eyes

}
}
}

My question is; is there anyway to modify the code so that when I swipe the rfid tag the helmet opens and stays open. When I swipe the tag again, it will close and stay like that until I swipe it again?

Thanks everyone for reading.

As an added bonus here is me with my friends last year with our costumes:

Add a boolean variable to keep track of whether the faceplate is open or closed. FacePlateOpen perhaps. When you get something from the tag, change the variable from true to false or vice versa. Then set the servos to their appropriate positions depending on whether the FacePlateOpen variable is true or false.

Thanks for the reply wildbill. I'm not familiar with booleans at all. Would you know the best way to incorporate it into this code?

#include "Servo.h" // include the servo library

Servo faceplateServo;
Servo chinServo;

int ledPin1 = 4; // control pin for LED eyes
int servoPin1 = 2; // control pin for face plate servo
int servoPin2 = 3; // control pin for chin
bool FacePlateOpen=false;

void setup() 
{
  faceplateServo.attach(servoPin1); // attaches the servo on pin 2 to the servo object
  chinServo.attach(servoPin2); // attaches the servo on pin 3 to the servo object
  faceplateServo.write(30); // rotate face plate servo to 30 degrees
  chinServo.write(95); // rotate chin servo to 95 degrees
  pinMode(ledPin1, OUTPUT); // sets the LED pin as output
  digitalWrite(ledPin1, HIGH); // turn on LED eyes
  Serial.begin(9600);
}

void loop() 
{
// look for a capital A over the serial port and turn off LED
if (Serial.available() > 0) 
  {
  if(Serial.read() == 'A') 
    { // reads tag over XBee
    digitalWrite(ledPin1, LOW); // turn off LED eyes
    delay(500); // wait half a second
    FacePlateOpen=!FacePlateOpen;
    if(FacePlateOpen)
      {
      chinServo.write(20);      // rotate the chin servo to 20 degrees
      faceplateServo.write(95); // rotate the face plate servo to 95 degrees
      }
    else
      {  
      chinServo.write(95);      // rotate the chin servo to 95 degrees
      faceplateServo.write(30); // rotate the face plate servo to 30 degrees
      }
    digitalWrite(ledPin1, HIGH); // turn on LED eyes
    }
  }
}

Wildbill you're the man!! It works! Thank you so much :slight_smile: :)!