Wednesday, December 10, 2014

      This is our final prototype.  The servo is taped into the cardboardbox and then glued to the catapult arm.  The arm itself is supposed to be made of 3D printed plastic material but there have been a lot of delays in getting this part fabricated, so this is our prototype as it stands.  The code involves using a button to control the firing of the catapult.  When the button is held down, a succesion of 3 LEDs are lit to act as a countdown.  The servo is then told to run and the arm goes about 120 degrees.  When the button is let go, the LEDs and the servo return to their normal states and wait for the button to be pressed again.

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