arduino- Multicoin +current credits = digital output? help

hello I have managed to connect my arduino with multiocoin acepter , when I open the serial monitor tells me that currency was introduced , but I want to add when the current credit is (5). pin output &(time delay), some help plis :smiley:

the code

const byte coinValues[4] = {
// money, money,50, 100};
#define pulseTimeout 50
#define actionTimeout 10000

unsigned long lastAction = 0;
unsigned long lastPulse = 0;
int pulseCount = 0;
int currentCredit;

void showCredit()
{
int credit = currentCredit/10;
int left = currentCredit % (currentCredit/10);

Serial.print("Current credit: ");
Serial.print(credit, DEC);
Serial.print(".");
Serial.print(left, DEC);
Serial.println("0");
}

void setup()
{
Serial.begin(115200);

attachInterrupt(1, acceptorPulse, RISING);

Serial.println("Coin Acceptor ready");
pulseCount = 0;

pinMode(13, OUTPUT);
}

unsigned long tempAction;
unsigned long tempPulse;

void loop()
{
tempAction = lastAction;
tempPulse = lastPulse;

if (millis() - lastPulse >= pulseTimeout && pulseCount > 0 || pulseCount >= 4)
{
if (tempAction != lastAction || tempPulse != lastPulse) return; //Check if interrupt has fired since loop started, wait for next cycle if it has

tone(12, 1800, 150);
currentCredit += coinValues[pulseCount-1];
showCredit();
pulseCount = 0;
}

if ((millis() - lastAction >= actionTimeout) && (lastAction != 0) && (currentCredit > 0) && (pulseCount == 0))
{
if (tempAction != lastAction || tempPulse != lastPulse) return; //Check if interrupt has fired since loop started, wait for next cycle if it has

currentCredit = 0;
lastAction = 0;
Serial.println("\n*** TIMEOUT! Credit reset. ***");
showCredit();
}
}

void acceptorPulse()
{
lastAction = millis();
lastPulse = millis();
pulseCount++;
}

void acceptorCount()
{
digitalWrite(13, digitalRead(13));
}

Hi,

Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom..... :slight_smile: