Hello, how can i insert the code to run the delay function on the interrupt? delay is not working with attachinterrupt but is there any way on how to do so that when i insert coin to the coin acceptor, the following code will work and then stop.
digitalWrite(8, HIGH);
delay(50);
digitalWrite(8, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
delay(500);
again when another coin inserted, that code will work then stop.
Here's my codes...
const int coinpin = 0;
int pin13 = 13;
int pin7 = 7;
int pin8 = 8;
volatile int cents = 0;
int credits = 0;
void setup () {
attachInterrupt(0, coinIn, RISING);
pinMode (pin13, OUTPUT);
pinMode (2, INPUT_PULLUP);
pinMode(pin7, OUTPUT);
pinMode (pin8, OUTPUT);
}
void loop () {
digitalWrite(8, HIGH);
delay(50);
digitalWrite(8, LOW);
delay(200);
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
delay(500);
//Turn off LED
digitalWrite(pin13, LOW);
}
void coinIn(){
//Do some stuff when a coin is inserted
cents = cents + 1;
digitalWrite (pin13, HIGH);
}