Video Teleconference Mic button pusher

Our VTC machine doesn’t allow for an external on/off switch for the microphone. I am attempting to make little gadget that activates a servo to push the mic button and switch between a red and green LED for cool visual purposes.

I’m still in prototype mode, with everything hooked up to a breadboard. I am running into an issue with my programming.

Everything looks fine when I power up, and the red LED comes on. When I push the button, the servo moves to the prescribed position, but doesn’t return like I had hoped that it would. (The green LED does come on though, so I feel pretty good about that part.

After I push the button again, (to reset the counter to 0,) the green LED switches off, the servo returns to the prescribed position, and the red LED comes on.

After rambling, my problem is that I can’t get the servo to go back after the delay while in counter == 1.

Am I going about this the wrong way by using a counter? I feel like there is a simpler/easier way to make this happen. However, my forum scraping and google skills have yielded me no joy.

Thank you in advance for helping out!

(This is also my first forum post, so I attached the .ino as well as pasted my code below.)

 #include <Servo.h>
 
 // pushbutton pin
 const int buttonPin = 2;
 //ledPin green
 int ledGreen = 13;
 //ledPin red
 int ledRed = 3;
 // servo pin
 const int servoPin = 9;
 Servo servo;
 // variable for counter for led lights
 int counter = 0;


void setup()
{
  servo.attach (servoPin);
  
  // Set up the pushbutton pins to be an input:
  pinMode(buttonPin, INPUT);
  // Turn on green LED light
  pinMode(ledGreen, OUTPUT);
  // Turn on red LED light
  pinMode(ledRed, OUTPUT);
}


void loop()
{
 // local variable to hold the pushbutton states
  int buttonState;  

  //read the digital state of buttonPin with digitalRead() function and store the value in buttonState variable
  buttonState = digitalRead(buttonPin);

  //if the button is pressed increment counter and wait a tiny bit to give us some          //time to release the button
  if (buttonState == LOW) // light the LED
  {
    counter++;
    delay(150);
  }

  //neutral state when power on or return to mic off, turns red light on and green off
 if(counter == 0){
   servo.write (20); // neutral position
   digitalWrite(ledRed, HIGH);
   digitalWrite(ledGreen, LOW);
 }
  // hits microphone switch to on and activates green light while turning off red light
  if(counter == 1){
   digitalWrite(ledGreen, HIGH);
   digitalWrite(ledRed, LOW);
   servo.write (90); // switching on
   delay(20); //pause to turn on
   servo.write (20); //back to neutral here
  }
  else{
    counter = 0;
  }
  
 
  
}

Finally, to give credit where credit is due, I took this code from UnicornClockworks instructables page and modified it.

vtc_push_button.ino (1.5 KB)

Edit:
I have also realized that I need to program in for the servo to turn the mic off when I want to go back into mute. So the code above is incomplete, however, I hope that when I figure out the "turn-on" portion, I'll be able to program the servo to hit the button again and switch the red LED on for "mute" mode.