I need help with my iron man faceplate project

I have found this code from the internet but there is a problem with it when pressing the button once it turns on light by on-off then on but I want to add when button press light flicker for 3 to 5 sec and fade in to turn on instead of turn on imedetly please help it's my dream project

#include <Servo.h>
int button = 2; //button, connect to ground
int press = 0;
Servo servo; //left servo looking out of helmet
Servo servo1; //right servo looking out of helmet
boolean toggle = true;


int leftServoOpen = 35;
int leftServoClosed = 145;
int rightServoOpen = 115;
int rightServoClosed = 0;
int ledPin = 13;
int offTime = 55;
int onTime = 0;


void setup()
{
  pinMode(button, INPUT); //arduino monitor pin state
  servo.write(leftServoOpen);
  servo.attach(9); //pin for servo 1 on pin 9
  servo1.write(rightServoOpen);
  servo1.attach(10); //pin for servo 2 on pin 10
  digitalWrite(2, HIGH); //allows pullup for pin high
  pinMode(ledPin, OUTPUT);
}


void loop()
{
  press = digitalRead(button);
  if (press == LOW)
  {
    if(toggle)
    {
      servo.write(leftServoOpen);
      servo1.write(rightServoOpen);
      servo.detach();
      servo1.detach();
      servo.attach(9);
      servo1.attach(10);
      toggle = !toggle;
      digitalWrite(ledPin, LOW);
      onTime = 55;
      offTime = 0;
    }
    else
    {
      servo.write(leftServoClosed);
      servo1.write(rightServoClosed);
      toggle = !toggle;


      delay(1000);
      digitalWrite(ledPin, HIGH);
      delay(100);
      digitalWrite(ledPin, LOW);
      delay(100);
      digitalWrite(ledPin, HIGH);
      delay(100);
      digitalWrite(ledPin, LOW);
      delay(500);
      digitalWrite(ledPin, HIGH);
    }
  }
  delay(500); //debounce delay
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

is thats ok will i get some help with the code

See how much easier it is to read the code. I cannot promise that you will get more help now but you have made it easier

you can help?

This has a very low likelihood of success using delays.
You can pull it off using millis() for your timing, and states to determine if the lights should be flickering and for how long before turning on completely.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.