Need Help with someone checking over my program and see if i have anything wrong

please check my program and see if I have anything wrong.

I'm trying to read pulses from coin acceptor (sensor) and depending on the pulses, different statements should be displayed

here, in the sensor I can program the sensor to give pulses as i want
for example for p1 coin i can set it to give 5 pulses and for p2 coin i can set it to give 10 pulses.
So I've programmed it to give
2 pulses for P1 coin
5 pulses for p2 coin
10 pulses for p3 coin

now the sensor gives pulse output which should be read in the arduino and if 5 pulses are detected it should display a message and if 10 pulses are detected it should displayanother message.

here, arduino should first detect all the pulses then activate the message because if it accepts the pulses as they come it'll be a problem because when 5 pulses come arduino might directly jump into 2 pulses loop and activate different message. please help

int coinPulseCount;
int newCoinInserted;
int coinPulse;
byte cmd = 0;
int opCountPin = 3;
volatile unsigned long pulseTime;





void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
Serial.print("INPUT on PIN");
Serial.print(opCountPin);
Serial.println();
pinMode(opCountPin, INPUT);
attachInterrupt(1, coinpulse, RISING);
}

void loop() {
  // put your main code here, to run repeatedly:
if(coinPulse >0 && millis()-pulseTime > 200)
{
  newCoinInserted = coinPulseCount ;
  coinPulseCount = 0;
}
switch(newCoinInserted)
{
  case 1:
 Serial.print("1 rupee");
 newCoinInserted = 0;
 break;
 
 case 2:
 Serial.print("2 rupee");
 newCoinInserted = 0;
 break;

 case 3:
 Serial.print("3 is inserted");
 newCoinInserted = 0;
 break;

 case 4:
 Serial.print("4 rupee inserted");
 newCoinInserted = 0;
 break;

 case 5:
 Serial.print("5 rupee inserted");
 newCoinInserted = 0;
 break;

 case 6:
 Serial.print("6 rupee inserted");
 newCoinInserted = 0;
 break;
}
}

void coinpulse()
{
    coinPulseCount++;
    pulseTime = millis();
}

Do fix your layout - ctrl-T in the IDE. Makes the code much more readable.

One issue: you didn't make coinPulseCount volatile.

Then: does the program work? If so, you're done (well, except the volatile issue).
If not, where does it go wrong?
How do you know all pulses have been received? What if the user pushes a few coins into the machine in quick succession?

wvmarle:
Do fix your layout - ctrl-T in the IDE. Makes the code much more readable.

One issue: you didn't make coinPulseCount volatile.

Then: does the program work? If so, you're done (well, except the volatile issue).
If not, where does it go wrong?
How do you know all pulses have been received? What if the user pushes a few coins into the machine in quick succession?

okay i made it volatile and I'm able to compile the program but i havent uploaded it yet and tried.
and there is slow fast toggle on the coin acceptor.

cyborg8274:
i havent uploaded it yet and tried.

Then start with that.

wvmarle:
Then start with that.

okie dokie

i uploaded the program but when i insert a coin i dont have any statement except "INPUT to PIN3"

What's with the sudden interest in money interfaces?

In the last two weeks, I've been approached by multiple people needing hardware or firmware written to read coin acceptors and bill acceptors.

Probably just coincidence, but strange.

cedarlakeinstruments:
What's with the sudden interest in money interfaces?

In the last two weeks, I've been approached by multiple people needing hardware or firmware written to read coin acceptors and bill acceptors.

Probably just coincidence, but strange.

I’m just working on college project. I don’t know about other people (•_•) so can you help me

cyborg8274:
I’m just working on college project. I don’t know about other people (•_•) so can you help me

Back in the day we did our own work in college. Guess I'm old fashioned and earned my degree.