i've been having a hard time on this code i want to run countdown when a coin is inserted what do you think is the problem with my code. when i insert a coin countdown starts.. if i insert another coin credit is still 1
stepbystep.ino (2.76 KB)
i've been having a hard time on this code i want to run countdown when a coin is inserted what do you think is the problem with my code. when i insert a coin countdown starts.. if i insert another coin credit is still 1
stepbystep.ino (2.76 KB)
Your showTime routine blocks forever since you test for seconds >=0. Once it is zero stepDown does not change it so it just sits in this while loop with seconds=0 and no other code can execute. Thus you can't see the next pulse from a coin.
while (hours > 0 || minutes > 0 || seconds >= 0) {
...
}
thnx mate! i think ill just rebuild this code from scratch
What is this supposed to do?
I don't think you are adjusting time with credits yet.
You can also optimize your show time by just keeping up with total seconds and converting those to hr:min:sec when you format the values for print.
void showTime() {
if (credits>0) {
while (seconds >= 0) {
char buffer[17];
sprintf(buffer, "Time: %02d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, (seconds % 3600) % 60);
lcd.setCursor(0, 1); // set timer position on lcd for end.
lcd.print(buffer);
lcd.display();
if (--seconds < 0) { //replaces trigger
lcd.setCursor(0, 0);
lcd.print("Credits: ");
lcd.setCursor(9, 0);
lcd.print(credits);
lcd.display();
break;
}
delay(1000);
}
seconds = 0;
}
}
Best of Luck! g'day.
Thanks for the help... I'm doing a simple school project that has to do with some relays, bill acceptor, and coin hopper.. a vendo computer rental which accepts bills and gives change to the user..