We created a rubber band sentry gun which can rotate to aim, and adjusts the rubber band launch angle. It includes two DC motors for lift and spin, and a solenoid which releases the rubber band.

See a test run of the sentry gun:

Here is a quick run through of the controls:



// Define the pin numbers on which the outputs are generated.
#define MOT_A1_PIN 5
#define MOT_A2_PIN 6
#define MOT_B1_PIN 9
#define MOT_B2_PIN 10
#define Spin A0
#define Lift A1
#define fire 3

int to_fire = 7;
long check = 0;
long time_fired = 0;

bool not_print = true;
bool not_fire = true;
// ================================================================================
/// Configure the hardware once after booting up.  This runs once after pressing
//// reset or powering up the board.
void setup(void)
{
  // Initialize the stepper driver control pins to output drive mode.
  pinMode(MOT_A1_PIN, OUTPUT);
  pinMode(MOT_A2_PIN, OUTPUT);
  pinMode(MOT_B1_PIN, OUTPUT);
  pinMode(MOT_B2_PIN, OUTPUT);
  pinMode(Spin, INPUT);
  pinMode(Lift, INPUT);
  pinMode(fire, INPUT);
  pinMode(to_fire, OUTPUT);
  digitalWrite(to_fire, LOW);

  // Start with drivers off, motors coasting.
  digitalWrite(MOT_A1_PIN, LOW);
  digitalWrite(MOT_A2_PIN, LOW);
  digitalWrite(MOT_B1_PIN, LOW);
  digitalWrite(MOT_B2_PIN, LOW);

  // Initialize the serial UART at 9600 bits per second.
  Serial.begin(9600);
}

// ================================================================================
/// Set the current on a motor channel using PWM and directional logic.
/// Changing the current will affect the motor speed, but please note this is
/// not a calibrated speed control.  This function will configure the pin output
/// state and return.
///
/// \param pwm    PWM duty cycle ranging from -255 full reverse to 255 full forward
/// \param IN1_PIN  pin number xIN1 for the given channel
/// \param IN2_PIN  pin number xIN2 for the given channel

void set_motor_pwm(int pwm, int IN1_PIN, int IN2_PIN)
{
  if (pwm < 0) {  // reverse speeds
    analogWrite(IN1_PIN, -pwm);
    digitalWrite(IN2_PIN, LOW);

  } else { // stop or forward
    digitalWrite(IN1_PIN, LOW);
    analogWrite(IN2_PIN, pwm);

  }
}
// ================================================================================
/// Set the current on both motors.
///
/// \param pwm_A  motor A PWM, -255 to 255
/// \param pwm_B  motor B PWM, -255 to 255

void set_motor_currents(int pwm_A, int pwm_B)
{

  set_motor_pwm(pwm_A, MOT_A1_PIN, MOT_A2_PIN);
  set_motor_pwm(pwm_B, MOT_B1_PIN, MOT_B2_PIN);

}



void loop(void)
{
  int spinMotor = analogRead(Spin);
  int liftMotor = analogRead(Lift);



  if(digitalRead(fire)){
    if(not_fire){
      not_fire = false;
      digitalWrite(to_fire, HIGH);
      check = millis();
      time_fired = millis();
      Serial.println("Fire");
    }
  }
  
  if(millis() - time_fired > 1000){
    if(!not_fire and not_print){
      not_print = false;
      Serial.println("Stop Firing");
    }
    digitalWrite(to_fire, LOW);
    time_fired = 0;
  }

  if(millis() - check > 3000){
    not_print = true;
    not_fire = true;
  }

  spinMotor = constrain(spinMotor, 100, 900);
  liftMotor = constrain(liftMotor, 100, 900);

  spinMotor = map(spinMotor, 100, 900, -75, 75);
  liftMotor = map(liftMotor, 100, 900, -255, 255);


  set_motor_currents(spinMotor, liftMotor);
}