I have used the cli() and sei() like you mentioned, still didn't fix the problem, here is my code Im i using it correctly?
const int coinInt = 0;
void setup()
{
// Debugging output
Serial.begin(9600);
Serial.println("Ready...");
pinMode (2,INPUT_PULLUP);
attachInterrupt(coinInt, coinISR, RISING); // COIN wire connected to D2;
}
// total amount of money collected;
float money = 0.0;
// gets incremented by the ISR;
// gets reset when coin was recognized (after train of pulses ends);
volatile int pulses = 0;
volatile long timeLastPulse = 0;
// executed for every pulse;
void coinISR()
{
pulses++;
timeLastPulse = millis();
}
void loop()
{
long timeFromLastPulse = millis() - timeLastPulse;
if (pulses > 0 && timeFromLastPulse > 200)
{
cli();
// sequence of pulses stopped; determine the coin type;
if (pulses == 1)
{
Serial.println("2 pulses");
money += .1;
}
else if (pulses == 5)
{
Serial.println("5 pulses");
money += .25;
}
else if (pulses == 10)
{
Serial.println("10 pulses");
money += 1.0;
}
else if (pulses == 15)
{
Serial.println("Received tooney (15 pulses)");
money += 2.0;
}
else
{
Serial.print("Unknown coin: ");
Serial.print(pulses);
Serial.println(" pulses");
}
pulses = 0;
sei();
}
}