Catapult controller Computer link need help

/*
 * /========================================================================================\
 * /= Program for controlling a catapult with a switch, servo and arduino                  =\
 * /=                                                                                                                 =\
 * /= Program moves servo to extreme minimum sto move  =\
 * /= a bolt / trigger pin then stays there until switch is flipped back to off position.  =\
 * /= Then back to extreme maximum when switch state is turned back to off.                =\
 * /========================================================================================\
 */
#include <Servo.h> 
 // Set digital pin numbers:
 const int servoPin = 9;  // The number of the Servo pin
 const int buttonPin = 6;  // The number of the Pushbutton pin
 const int buzz = 2; //sets pin for buzzer
 int buttonState = 0;  // Variable for reading the pushbutton status
 
   // Variable for reading direction of the servo

 Servo myservo;  // Create servo object to control a servo 

 int pos = 0;  // Variable to store the servo position 
 

 void setup() {
   myservo.attach(8);  // attaches the servo on pin 8 to the servo object 
   pinMode(buttonPin, INPUT);  // initialize the pushbutton pin as an input
   pinMode(buzz, OUTPUT); //Buzzer pin
 }

 void loop(){
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);

       //The button is pushed
     if (buttonState == LOW) {
      // The direction for the servo is clockwise

       // goes from 0 degrees to 180 degrees in steps of 1 degree
       pos = 0;
       
         myservo.write(pos);  // tell servo to go to position in variable 'pos' 
         delay(15);  // waits 15ms for the servo to reach the position 
      
     
     }
     // The button is pushed
     else if(buttonState == HIGH) {
        // The direction for the servo is anti-clockwise 

       // goes from 180 degrees to 0 degrees in steps of 1 degree 
      pos = 180;

        digitalWrite(buzz, HIGH);
        delay (600);
        digitalWrite(buzz, LOW);
        delay (600);
        digitalWrite(buzz, HIGH);
        delay (500);
        digitalWrite(buzz, LOW);
        delay (500);
        digitalWrite(buzz, HIGH);
        delay (400);
        digitalWrite(buzz, LOW);
        delay (400);
        digitalWrite(buzz, HIGH);
        delay (300);
        digitalWrite(buzz, LOW);
        delay (300);                      
         myservo.write(pos);  // tell servo to go to position in variable 'pos' 
         delay(15);  // waits 15ms for the servo to reach the position 
       hold:
       buttonState = digitalRead(buttonPin);
       if(buttonState == HIGH){
        delay(10);
        goto hold;
 }}}

It works with hardware just wire the proper pins on ad the switch I used is a spst safety switch from radio shack. The servo I am using is a JR ST47BB I will post a video of it in action once the catapult is finished. ANy suggestions to improve the code greatly appreciated mostly bug free busser still goes off randomly. The purpose of this is to control a huge catapult by releasing a spring loaded pin with a servo motor. How should i add status leds like for armed and launching? Also pc control possible with pi running server and sending serial data or a processing app?? Please advise. I am using a arduino uno. I want to add a software layer to this but i don’t know how with out destroying the hardware interface.

skiboss: ANy suggestions to improve the code greatly appreciated

  • Use Tools > Auto Format this will make it easier for you to see what is going on in your program and find bugs and will also make it easier for people on the forum to read.
  • Get rid of the hold: goto loop. Don't ever use goto unless you have a very good reason. Once you start adding in other features like PC control you will need to have non-blocking code.

skiboss: How should i add status leds like for armed and launching?

You'll need to provide more information on this question. Are you asking how to wire the LEDs or how to control them in your sketch or both?

skiboss: Also pc control possible with pi running server and sending serial data or a processing app??

Sure, either one should be pretty easy, but why would you need that?

The status led doesn't matter I just need the pc communication.