Working with coin acceptor using delay.

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);

}

Why would you want to delay an interrupt?

What i want to do is when i insert a coin, say a motor will run for an period of time, example for 3 seconds.

OK, so why does that need an interrupt?

because i think code that will work on the coin acceptor is attachinterrupt .

Well, I can't see your code, but that doesn't seem very likely to me.
Interrupts are for events (no pun intended) that happen on sub-millisecond timing scales.
Very little about the motion of a coin would seem to me to fit that description

the code that i attached before was wrong.
here is my code...

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);

}

the code that i attached before was wrong

It's still wrong - it's got delay()s in it.

is there any way i can do so that it will work what i wanted to?

Yes, of course.
You just have to explain in simple terms exactly what it is you want to do.

NB "clear terms" does not include

int pin13 = 13;
int pin7 = 7;
int pin8 = 8;

Can you give us more details about your coin acceptor, please?

Does it give an output pulse of say 100ms width?
Are there separate outputs for different coins?

A link to the manufacturer's datasheet would be useful.

AWOL:
Yes, of course.
You just have to explain in simple terms exactly what it is you want to do.

NB "clear terms" does not include

int pin13 = 13;

int pin7 = 7;
int pin8 = 8;

what i want is to run the dc motor in forward stop reverse stop, i connected it to a 2 module relay. and i used these code

digitalWrite(8, HIGH);
delay(50);
digitalWrite(8, LOW);
delay(200);

digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
delay(500);

Now im trying to do it with coin acceptor. That whenever I insert one peso coin, that code for the dc motor will work.

It is a multi coin acceptor. Can accept
1 - peso coin = 1 pulse
5 peso coin = 5 pulse
and
10 peso coin = 10 pulse

regards. :slight_smile:

JohnLincoln:
Can you give us more details about your coin acceptor, please?

Does it give an output pulse of say 100ms width?
Are there separate outputs for different coins?

A link to the manufacturer's datasheet would be useful.

It is a multi coin acceptor. Can accept

1 - peso coin = 1 pulse
5 peso coin = 5 pulse
and
10 peso coin = 10 pulse

Pin 8 or pin 7 means absolutely nothing to us (or you in six months time) - give them descriptive names.