Go Down

Topic: Iron man helmet faceplate and LED (Read 8317 times) previous topic - next topic

digitalfa

Hey guys i'm new to the Arduino and i have a Arduino Uno and i don't know how to write the code.
Can some pro please write me a simple code which turn 180 to open up the faceplate and LED turn off with a press of a button, then if press again it will turn back 180 counter clock wide to close the faceplate then turn on the LED.

johnwasser

#1
Jan 12, 2013, 12:28 am Last Edit: Jan 12, 2013, 12:32 am by johnwasser Reason: 1
Code: [Select]

const int servoPin = 2;
const int buttonPin = 3;
const int LEDPin = 4;

#include <Servo.h>

Servo visorServo;

void setup() {
  visorServo.write(0);  // Initial position
  visorServo.attach(servoPin);

  pinMode(buttonPin, INPUT_PULLUP);  // Connect button between pin and GROUND. LOW when pushed.

  pinMode(LEDPin, OUTPUT);
  digitalWrite(LEDPin, LOW);  // LED off
}

void loop() {
  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) {
      visorServo.write(180); // Open visor
      visorClosed = false;
      digitalWrite(LEDPin, HIGH); // Turn on light
    }
    else {  // Viso is open
      visorServo.write(0); // Close visor
      visorClosed = true;
      digitalWrite(LEDPin, LOW); // Turn off light
    }
  }
 
  lastButtonState = newButtonState;
}

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

PeterH


johnwasser

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

tcengs

thread back from the dead, i am starting a similar project and the code provided works wonders , however i am trying to include a 2nd servo that moves in the opposite position as the 1st servo. i am new an dont know where to start. didnt mean to high jack 

johnwasser

It's not hard to add a second servo:
Code: [Select]

const int servo1Pin = 2;
const int buttonPin = 3;
const int LEDPin = 4;
const int servo2Pin = 5;

#include <Servo.h>

Servo visorServo1;
Servo visorServo2;

void setup() {
 visorServo1.write(0);  // Initial position
 visorServo1.attach(servo1Pin);

 visorServo2.write(180); // initial position
 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() {
 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(180); // Open visor
     visorServo2.write(0);
     visorClosed = false;
     digitalWrite(LEDPin, HIGH); // Turn on light
   }
   else {  // Viso is open
     visorServo1.write(0); // Close visor
     visorServo2.write(180);
     visorClosed = true;
     digitalWrite(LEDPin, LOW); // Turn off light
   }
 }
 
 lastButtonState = newButtonState;
}
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

tcengs

its been 15 years since I've written code. Thanks for the quick reply

arielcosco

como hago para que el servo suba despacio en la apertura?

Phop

Sorry to ask but im not good with any of this bought a kit cant work it out but can follow a diagram, would some one be able to post one of how the board would be set up

cedarlakeinstruments

Besides the fact that you're dredging up a 5 year-old thread, what kit? what board? Set up for what?


Sorry to ask but im not good with any of this bought a kit cant work it out but can follow a diagram, would some one be able to post one of how the board would be set up
Electronics and firmware/software design and assistance. No project too small

Phop

So at the top of this post is a sketch for a iron man helmet. I want to know how to set up the breadboard and how to wire it up

xl97

Have you done a search?

This topic has been posted before..

Also.. maybe check out:  www.therpf.com  where prop makers hang and show their work..

many diagrams and code there for this type of project.


Phop

Hi pal already found your post followed and build thanks for that helped loads. Just came across this first and asked the question but sorted thank to you cheers

Go Up