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();
}