Arduino- COINSLOT to SERVOMOTOR - Pulses. Need Help.

Hi... really need help on this.

IS THERE ANY OTHER WAY TO COUNT OCCURRING PULSES FIRST BEFORE ENTERING THE CONDITIONS IN THE LOOP?

By counting first all occurring pulses the system can identify what type of coin was inserted and move the servo motor to each degree with respect to the type of coin inserted.
TYPE 1 coin = 1 pulse.
TYPE 2 coin = 5 pulses.
TYPE 3 coin = 10 pulses.

With the limited knowledge i have i used a function with delay in it that is being called as a temporary solution to count first all occurring pulses. With the "Counter" function it gives the system the ability to count pulses first before entering the conditions.

#include <Servo.h>
#include <EEPROM.h>
Servo myservo;

volatile int coins = 0;
volatile int CoinChange = 0;
int CoinSub1 = 10;
int CoinTotal;
int COne;
int CFive;
int CTen;

void setup()
{
  myservo.attach(9); 

//CoinSlot
EIFR = _BV (INTF0);
  pinMode(2,INPUT_PULLUP);
  attachInterrupt(0, coinInserted, FALLING);
//coinslot
}

void coinInserted(){
  coins = coins + 1;  
  CoinChange = 1; 
}

void Counter(){
  delay(1500);
  delay(900);
}

void loop()
{
  COne = EEPROM.read(4);
  CFive = EEPROM.read(6);
  CTen = EEPROM.read(8);
  CoinTotal = (COne*1) + (CFive*5) + (CTen*10);

  Counter();
  delay(900);

  CoinSub1 = CoinSub1 - coins;

if(CoinChange == 1){
  if (CoinSub1 == 9/*coins == 1*/)
  {
     if(COne < 50 && CoinTotal <= 799)
     {
       COne = COne + 1;
       EEPROM.write(4, COne);
       myservo.write(30);
     }
  }
  else if (CoinSub1 == 5/*coins == 5*/)
  {
    if(CFive < 50 && CoinTotal <= 795)
    {
       CFive = CFive + 1;
       EEPROM.write(6, CFive);
       myservo.write(50);
    }
  }
  else if (CoinSub1 == 0/*coins == 10*/)
  {
     if(CTen < 50 && CoinTotal <= 790)
     {
       CTen = CTen + 1;
       EEPROM.write(8, CTen);
       myservo.write(70);
     }
  }
CoinSub();
}
}
void CoinSub(){
CoinSub = 10;
}

BUT with this coding, with repetitive insertion of coins, the ACCURACY isn't 100% because even if there is still pulses occurring it enters the conditions within the loop which results in a wrong identification of coin. And another result of this coding is that the response time of the servo motor to move in the degree respective to the coin inserted after a coin is inserted in the system is 3-5 seconds.

FOR EFFICIENCY, i require the system to be always 100% in identifying the coins being inserted and a much faster response time.

Gedon:
IS THERE ANY OTHER WAY TO COUNT OCCURRING PULSES FIRST BEFORE ENTERING THE CONDITIONS IN THE LOOP?

That question really doesn't make any sense, and shouting it at us doesn't help.

I see from some of your other threads that shouting a question is your standard technique, for example:

WHAT IS THE RANGE OF VOLTAGE AND CURRENT NEEDED TO TURN ON ARDUINO UNO.?

All-caps sentences are considered rude. Please stop doing that.

i'm sorry to have made a bad impression and for being rude to the other people reading this topic. :frowning:

let me rephrase my question:

as i am using a coin acceptor that generates pulses depending on the coin being inserted in the coin acceptor,
What can i do to program the arduino uno to identify as well the type of coin inserted in the coin slot using the pulses generated?
What codes should i use?

again, i'm sorry for being rude.

When a coin is inserted, how far apart are the pulses? If the time between pulses is relatively constant, you could expect the next pulse to be some many milliseconds (or microseconds) later, for a multi-pulse coin. If no pulse arrives within that window, you know that all the pulses for that coin have arrived.

Once you know that all the pulses have arrived, you know the value for the coin. You also know not to do anything about/with the value of a coin during the window that pulses could arrive.