Making a Vending Machine from a Arduino Esplora and a Adafruit Coin Acceptor

Hello,
This post is NOT about the feasibility of my plan but rather how to write the code for the project.
The general plan is to count quarters using the coin acceptor that works off of pulses, store number of coins, on button press operate servo, and finally remove 50 cents or two coins from the count, and then obviously loop. Using the github code (avaliable here: https://raw.githubusercontent.com/adafruit/Adafruit-Programmable-Piggy-Bank/master/piggybank.ino) I extrapolated this much:

#define COIN 2
int coins;

void setup() {

  pinMode(COIN, INPUT);
  digitalWrite(COIN, HIGH);
  coins = 0;
}

void loop() {
 
  uint8_t counter = 0;
  while (digitalRead(COIN)) {
    delay(1);
    counter++;
  }
  Serial.print(counter);
  Serial.println(" ms long pulse");
  
  if ((counter > 60) || (counter < 20))
      return;
	
}

And now I don't know where to go.

Any help would be much appreciated,
Alpha

P.S.- I know I could use a different board but this is what I have right now,
also at the moment I am not interested in putting in a LCD notification.

Thanks in Advance!

And now I don't know where to go.

Obviously, you want to do something if counter is between 20 and 60. So, put that in and else block after the if statement at the end of loop().

It seems that in that block, you want to read the state of a switch, and, if it is pressed, activate a servo.

Do NOT reset counter on every pass through loop(). Only reset it when you have done something with the servo.

you need to make a plan like this

person enters a coin. it can only be a quarter. Any other coin will be rejected
(how, any indication that its rejected, led ?)

person enters the second coin.

if 2 coins are detected and neither is rejected then run drink cycle

(how does the person know that neither has been rejected and they can proceed? )

update record that 2 coins have been added. (why would you minus?)

(would a third coin be automatically rejected based on the arduino knowing it doesn't require a 3rd coin?)

(how do you retrieve this record?)

what steps are required to make the drink
(does the person have options?)

as making a drink may require a lot of programming to monitor temperature etc your code should be designed as none blocking so avoid delay or using while. To assist in troubleshooting think about adding some sort of visual aid like leds as steps are meet. (you may not be planning to do anything other than dispensing a empty cup at the moment but writing code that can be expanded later will make life easier)

a good design in small easy to read steps is real close to what the finished code will look like.