Hi.
Am using a modified code from Mr. Raynerd (coin machine) for my purposes but i can not find what am missing in the pulse count.
If i insert one euro i will get:
new coin - 1 EUR -----> OK
But if i insert 2 or 5 i will get :
new coin - 1 EUR
new coin - 1 EUR
new coin - 1 EUR
new coin - 1 EUR
new coin - 1 EUR
new coin - 1 EUR
new coin - 1 EUR
So, it's counting OK but it doesn't go into case 2 / 3.
Code:
//#include <LiquidCrystal.h>
//LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
//**************Variables ****************
volatile byte coinPulseCount=0; // a counter to see how many times the pin has changed - which coin inserted
volatile byte hopperPulseCount = 0; // a counter to she how many coins have been ejected
volatile unsigned long pulseTime; //this stores the time of the last pulse.
byte newCoinInserted; // a place to put our last coin pulse count
byte coinValue = 0; // number of pulses required to dispence each coin type.
//***************************
byte pulseThreshold = 200; // for alberichi coin sorter
//***************************
void setup()
{
Serial.begin(9600);
//lcd.begin(16, 2);
pinMode (2,INPUT_PULLUP);
attachInterrupt(0, coinacceptor, FALLING);
}
//*****************************************************
void loop()
{
//lcd.setCursor(1,0);
//lcd.print(coins);
if (coinPulseCount >0 && millis()- pulseTime > pulseThreshold)
{
newCoinInserted = coinPulseCount;
Serial.print("New coin ");
coinPulseCount = 0;
}
switch (newCoinInserted) {
case 1:
Serial.println("1 EUR ");
newCoinInserted = 0;
break;
case 2:
Serial.println("2 EUR");
newCoinInserted = 0;
break;
case 3:
Serial.println("5 EUR");
newCoinInserted = 0;
break;
}
}
//*****INTERUPT for coin puls ****************
void coinacceptor()
{
coinPulseCount++;
pulseTime = millis();
}
Ideas ?