Saturday, December 13, 2014

Highlighted in red shows the changes that we made to the code.  The changes helped to allow the catapult to shoot completely before returning back to its original position.  Before this change, if the button was let go before the arm was finished shooting it would stop in the middle of its path and go back.  This change will avoid this from happening and make the prototype much more user friendly.  We were unable to get the part 3D printed for the catapult arm due to it being a part that was not compatible or able to be 3D printed for some reason.  The pieces for the box should have been laser cut to create a much more exact prototype.  The design was an overall success and we are happy with the final result.  The project could have been improved by the use of a motor instead of the servo since the motor would have given the "ammo" a much higher velocity and worked better.
Arduino Code
Parts Files

#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 (250);   
  } 
  else {
    delay (250);
    digitalWrite(ledPin1, LOW); 
   digitalWrite(ledPin2, LOW);
   digitalWrite(ledPin3, LOW);
  delay (100);
    myservo.write(0);
    delay (15);
  }
}

No comments:

Post a Comment