hi im having trouble with the code for my iron man helmet ive managed to get it working but the servo speed is to fast and the faceplate slams shut in totaly new to arduino and codeing its took me a long time to peice things together to get it to open and close with a press of a button and light up the led eyes and could use help with my code thanks for any help you can give
const int servo1Pin = 2;
const int buttonPin = 3;
const int LEDPin = 4;
const int servo2Pin = 5;
int buttonread;
#include <Servo.h>
Servo visorServo1;
Servo visorServo2;
void setup() {
Serial.begin(9600);
visorServo1.write(105); // Initial position CLOSED
visorServo1.attach(servo1Pin);
visorServo2.write(150); // initial position CLOSED
visorServo2.attach(servo2Pin);
pinMode(buttonPin, INPUT_PULLUP); // Connect button between pin and GROUND. LOW when pushed.
pinMode(LEDPin, OUTPUT);
digitalWrite(LEDPin, LOW); // LED off
}
void loop() {
Serial.println(buttonread);
delay(200);
static unsigned long lastPushedTime = 0;
static boolean visorClosed = true;
static boolean lastButtonState = HIGH;
boolean newButtonState = digitalRead(buttonPin);
// If the button is down and it has been a while since it was last down...
if (newButtonState == LOW && lastButtonState == HIGH && millis() - lastPushedTime > 100) {
lastPushedTime = millis();
if (visorClosed) {
visorServo1.write(0); // Close visor
visorServo2.write(43);
visorClosed = false;
digitalWrite(LEDPin, LOW); // Turn oFF light
}
else { // Viso is open
visorServo1.write(105); // Close visor
visorServo2.write(150);
visorClosed = true;
digitalWrite(LEDPin, HIGH); // Turn oN light
}
}
lastButtonState = newButtonState;
}