Attach interrupt query

Hi all, I am new to the Ardunio programming, a total of 1 day experience. I am writing this code to work as a 1s up counter. I have the counter working but now I need to attach a button so that when pressed once it will halt the counter, pressed twice counter continues. I am using an attach interrupt to achieve this. My code stops the counter when pressed but only does so while the button is being pressed. I would like it to stop when pressed once and then continue when pressed again. Any help would be appreciated.

gd_Tf_3.ino (2 KB)

 if (buttonState == RISING)

How is a digitalRead ever going to return 3?

[quote How is a digitalRead ever going to return 3? [/quote]

Return 3? sorry I am lost.

buttonState = digitalRead(Button);
if (buttonState == CHANGE)
{LED_PATTERN = LED_PATTERN++; //Increment pattern
delay (100); }              //1 s between increments
 if (buttonState == RISING)

digitalRead returns the values HIGH (1) or LOW (0). It is never going to return the value RISING (3)

AWOL: It is never going to return the value RISING (3)

OK I get that now, I have changed the code to

void loop() { buttonState = digitalRead(Button); if (buttonState == HIGH) {LED_PATTERN = LED_PATTERN++; //Increment pattern delay (100); } //1 s between increments if (buttonState == LOW) {LED_PATTERN = LED_PATTERN;

I have changed the code to

And? Now it works?

PaulS: And? Now it works?

It will stop the counter and hold the pattern when the button is pressed but only when pressed. I would like it to stop when pressed once, start when pressed twice, repeat.

You need to look into the State Change Detection example. You want to do something when the switch BECOMES pressed, not IS pressed. Or BECOMES released, not IS released.

Nothing in what you are doing appears to need interrupts.

I am new to the Ardunio programming, a total of 1 day experience.

Especially under these circumstances.

Learn about the Tools + Auto Format menu item. Your code looks like crap the way it is indented. There is no need for that.

PaulS: You need to look into the State Change Detection example. You want to do something when the switch BECOMES pressed, not IS pressed. Or BECOMES released, not IS released.

Nothing in what you are doing appears to need interrupts.

I am following instructions that tell me to use an interrupt. I just cant figure it out.

Learn about the Tools + Auto Format menu item. Your code looks like crap the way it is indented. There is no need for that.

Yes I will learn about Tools + Auto Format I agree my code looks like crap

yanamada22: I am following instructions that tell me to use an interrupt. I just cant figure it out.

Do you mean that this is an academic exercise and your tutor has instructed you to use interrupts in your solution? It's possible, but not a particularly sensible way to tackle the problem.