iron man eyes

so i am working on a iron man helmet and i want the eyes to ligt up when the helmet closes,
i have 2 servo's in the helmet and i want to add the lights to it.

can anyone help me??

servo helmet.txt (1.95 KB)

For short programs please include them in your Post so we don't have to download them. I will do it this time.

#include <Servo.h> 

Servo myservo;  // create servo object to control a servo 
Servo myservo2;  // create 2nd servo object to control a 2nd servo 

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to

// Variables will change:
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
int buttonPushCounter = 0;   // counter for the number of button presses
boolean currentButton = LOW;

void setup() {
  // attach the Servo to pins
   myservo.attach(9);
   myservo2.attach(10);
  // tell servo to go to position in variable 'pos'
  myservo.write(0);
  myservo2.write(0);
  
  delay(15); 
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
}

boolean debounce(boolean last)
{
  boolean current = digitalRead(buttonPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(buttonPin);
  }
  return current;
}


void loop() {
  // read the pushbutton input pin:
  buttonState = debounce(buttonPin);
  
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // went from off to on:
      buttonPushCounter++;
    } 
    else {
    }

    // save the current state as the last state, 
    //for next time through the loop
    lastButtonState = buttonState;
  }
  
  // moves the servo every other button push by 
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of 
  // the division of two numbers:
  if (buttonPushCounter % 2 == 0) {
  //move to position 90  
   myservo.write(180); 
   myservo2.write(0); 
   delay(15); 
  } else {
  //OR: move back to position 0  
   myservo.write(0); 
   myservo2.write(180 );
   delay(15); 
  } 
}

And if you do need to attach a longer program please attach it as a .ino file

...R

What have you tried in order to add the lights? And what are you having a problem with?

...R

Do you have a pulldown resistor on the button switch? You have not enabled the internal pullup and the switch seems active high, so a pulldown resistor is required to prevent the switch from floating. The most common way to wire a switch is from input to ground with the internal pullup enabled with pinMode(pin, INPUT_PULLUP). The logic is then, not pushed is HIGH and pushed is LOW.

dutch4years:
so i am working on a iron man helmet and i want the eyes to ligt up when the helmet closes,
i have 2 servo's in the helmet and i want to add the lights to it.

can anyone help me??

You can use the if..else statement in your code that sets the servos open or closed.
Put digitalWrite(LED,HIGH) in the part where the helmet servos are set to close, and digitalWrite(LED,LOW) where the helmet servos are set to open.
Tom.... :slight_smile:

i think i did it wrong.... what did i miss i am realy trieng to lern arduino

dutch4years:
i think i did it wrong....

What do you think you did wrong?

What do you think of the comments that have already been made?

Help us to help you.

...R

Hi,
Post the code you edited that went wrong, please, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom.. :slight_smile: