Here's some code which might help you at least as far as some logic is concerned.
My hardware is nothing like yours so:
- Coin acceptor is a single button which I had to debounce due to poor quality. Each press is 10p
- I just have a red led to come on to indicate it's operational
This is a state machine with 3 states, WAITING, ARMED and POWER_ON explained in sketch comments. States are handled in a switch... case where each does its thing with some leds and moves to next state when appropriate. When the timer turns the power off, it goes back to WAITING.
I also have the led on pin 13 doing a continuous Blink WithOut Delay to indicate none of the code is doing any blocking, which would prevent any other code from working properly.
//http://forum.arduino.cc/index.php?topic=459230
// coin operated power supply
//states are:
//WAITING for money
// blue led means no money yet
// blue and green led means 10, 20, 30, 40p has been inserted
//ARMED 50p inserted, awaiting start button
// green only led means 50p and waiting start
//POWER_ON working
// red only led
// stays on for 5 seconds (not the real 15 minutes)
//I don't have a coin box so using a button to mean 10p inserted
//coin button is debounced becuase my buttons are crap
// used Bounce2 library
//pulse is a delay()-less blink on 13 to prove nothing blocks
//
//button pins
byte coinButton = 8; //mimics 10p inserted
byte startButton = 9; //turn on power
//led pins
byte POWER_ONled = 2; //red
byte ARMEDled = 3; //green
byte WAITINGled = 4; //blue
//timing
unsigned long currentMillis;
//power timing
unsigned long poweredOnAt;
int powerOnFor = 2000; //not 15m for test
bool weAreTiming = false;
//pulse timimg
unsigned long previousPulse = 0;
byte pulseInt = 250;
bool pulseState;
//money
byte insertedSoFar = 0;
bool coinButtonState;
bool coinButtonStatePrev = true;
//states
enum { WAITING, ARMED, POWER_ON} currentState = WAITING;
//coinButton needs debouncing
#include <Bounce2.h>
Bounce dbCoin = Bounce();
void setup() {
// put your setup code here, to run once:
//leds
pinMode(POWER_ONled, OUTPUT);
digitalWrite(POWER_ONled, LOW);
pinMode(ARMEDled, OUTPUT);
digitalWrite(ARMEDled, LOW);
pinMode(WAITINGled, OUTPUT);
digitalWrite(WAITINGled, LOW);
pinMode(LED_BUILTIN, OUTPUT); //pulse
//buttons
pinMode(coinButton, INPUT_PULLUP);
pinMode(startButton, INPUT_PULLUP);
//debounce
dbCoin.attach(coinButton);
dbCoin.interval(50);
}
void loop() {
// put your main code here, to run repeatedly:
currentMillis = millis();
//always update the debouncer
dbCoin.update(); //dbCoin.read() to read
pulse(); //blink the heartbeat
//now sit in each state
//states show certain leds and await buttons to move to new state
//power state reverts to waiting when time is up
switch (currentState) //WAITING, ARMED, POWER_ON
{
case WAITING:
digitalWrite(WAITINGled, HIGH);
//handle a coin
coinButtonState = dbCoin.read();
if (coinButtonState != coinButtonStatePrev) //it changed
{
if (coinButtonState == LOW) //new press = new coin
{
digitalWrite(ARMEDled, HIGH);
insertedSoFar = insertedSoFar + 10;
}//coin button new press
}//coin button change
coinButtonStatePrev = coinButtonState;
//got 50p yet?
if (insertedSoFar == 50)
{
insertedSoFar = 0; //for next time
digitalWrite(WAITINGled, LOW);
currentState = ARMED; // moving on....
}//got 50
break;
case ARMED:
digitalWrite(ARMEDled, HIGH);
if (!digitalRead(startButton)) //active low
{
digitalWrite(ARMEDled, LOW);
currentState = POWER_ON; // moving on....
}//start
break;
case POWER_ON:
digitalWrite(POWER_ONled, HIGH);
if (!weAreTiming)
{
weAreTiming = true;
poweredOnAt = currentMillis;
}
if (weAreTiming)
{
if (currentMillis - poweredOnAt >= powerOnFor) //we done
{
digitalWrite(POWER_ONled, LOW);
weAreTiming = false;
currentState = WAITING; // moving on....
}
}
break;
}//switch
}//loop
void pulse()
{
if (currentMillis - previousPulse >= pulseInt)
{
digitalWrite(LED_BUILTIN, pulseState);
pulseState = !pulseState;
previousPulse = currentMillis;
}
}//pulse