Hi, need help on some programming problem.
I have already post a question about the interface of a coin acceptor to Arduino Uno,
http://arduino.cc/forum/index.php/topic,138209.msg1038645.html#msg1038645and just wanted to repost and add another concern about the programming.
In the display, i want to display the Total of the Coins and the number of the coins inserted.
With this code i can't seem to get what i want to display.
x = number of Type 1 Coin
y = number of Type 2 Coin
z = number of Type 3 Coin
a = monetary total of the coins inserted
So here is my code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);
volatile int coins = 0;
volatile int x = 0;
volatile int y = 0;
volatile int z = 0;
int a = 0;
void setup()
{
lcd.begin(16, 2);
//CoinSlot
EIFR = _BV (INTF0);
pinMode(2,INPUT_PULLUP);
attachInterrupt(0, coinInserted, FALLING);
//CoinSlot
}
//CoinSlot
void coinInserted()
{
coins = coins + 1;
CoinChange = 1;
}
void loop()
{
delay(1000);
if(coins == 1){
x = x + 1;
a = a + 1;
}
else if (coins == 5){
y = y + 1;
a = a + 5;
}
else if (coins == 10){
z = z + 1;
a = a + 10;
}
lcd.setCursor(1,0);
lcd.print(x);
lcd.setCursor(4,0);
lcd.print(y);
lcd.setCursor(7,0);
lcd.print(z);
lcd.setCursor(1,1);
lcd.print(a);
coins = 0;
}
What happens is that i have setup 4 variables that will be displayed in the LCD. I was hoping that with the 1 second delay it would have given the interrupt function the time it needs to count up the "coins" variable before entering the Loop function. But as a result it either does count right or only counts up the "x" variable even when the i have use Type 2 or 3 coins.
Need HELP.