interrupt programming

How long are these pulses?

Let's assume that each pulse is about 100ms long and that there's a gap of 100ms between pulses. There should be a 20ms debounce, and when there has been 250ms without a pulse, then we can assume that the train of pulses is complete.

int pulseCount;
uint32_t mostRecentChange_ms;
byte pinRead;

void loop() {
  if(millis() - mostRecentChange_ms < 20) return; // debounce

  byte prevRead = pinRead;
  pinRead = digitalRead(the pin);
  
  if(prevRead != pinRead) mostRecentChange_ms = millis();

  if(pinRead == HIGH && prevRead == LOW) {
      pulseCount ++;
  }

  if(pinRead == LOW && millis() - mostRecentChange_ms >= 250 && pulseCount > 0) {
    switch(pulseCount) {
      case 2:
        activate the 2-pulse solenoid;
        break;
      case 5:
        activate the 5-pulse solenoid;
        break;
      case 10:
        activate the 10-pulse solenoid;
        break;
      default:
        activate the unrecognised coin solenoid;
        break;
    }

    pulseCount = 0;
  }
}

I always like doing people's homework for them. It cheapens the value of having a qualification. I don't have a degree, but I do have experience, so this works out well for me.