Here is the code used for the arduino.
#include <Servo.h> 
const int buttonPin = 5;
const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 4; 
Servo myservo; 
int pos = 0;
int buttonState = 0;
void setup() 
{ 
  myservo.attach(9);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
} 
void loop() 
{ 
  buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {     
    delay (15);
    digitalWrite(ledPin1, HIGH);
    delay (500);
    digitalWrite(ledPin2, HIGH);
    delay (500);
    digitalWrite(ledPin3, HIGH);
    delay (500);
    myservo.write(120);
    delay (1);   
  } 
  else {
    delay (5);
    digitalWrite(ledPin1, LOW); 
   digitalWrite(ledPin2, LOW);
   digitalWrite(ledPin3, LOW);
  delay (100);
    myservo.write(0);
    delay (15);
  }
}
Here is a working prototype of our project:

No comments:
Post a Comment