how to end void loop temporarily without pressing arduino reset button

my program is like this
when there is light motor pulling up curtain
when there is no light,motor pulling down curtain
after i press interrupt, user pull the curtain manually with 2 interrupt button(pulling up or down)
after interrupt it will jump back to void loop continously,motor rotate automatically
it doest not make any sense if after interrupt jump back to void loop...
no point to press the interrupt if jump back to void loop
i need a button to control on/off the void loop...

Make a button that toggles a flag. And make an make the code do nothing while the flag is high.

can u explain the code to me? please..im still new to c...

Well, i'm writing this on my phone, but i'll give you this pseudo code.

Bool flag = FALSE;

void do_nothing()
{
Serial.print("pause");
}

Void loop()
{
/*your ordinary code goes here*/

If (button pressed)
{
Flag = !flag;
}

While (flag == true)
{
Do_nothing()
}

}

Hopefully this will give you an idea

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5 , 4, 3, 2);

int LDR=22;
int IN1 = 52;
int IN2 = 50;
int IN3 = 48;
int IN4 = 46;
int _step = 0;
int button=31;
boolean flag = false;

boolean dir = true;// gre
void anticlockwise()
{
switch(_step){
case 0:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);

break;
case 1:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
case 2:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 3:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 4:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 5:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 6:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 7:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
break;
default:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
}

if(dir){
_step++;
}else{
_step--;
}
if(_step>7){
_step=0;
}
if(_step<0){
_step=7;
}

delay(1);

}

void clockwise()
{

switch(_step){
case 0:
digitalWrite(IN4, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN1, LOW);

break;
case 1:
digitalWrite(IN4, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN1, HIGH);
break;
case 2:
digitalWrite(IN4, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN1, LOW);
break;
case 3:
digitalWrite(IN4, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN1, LOW);
break;
case 4:
digitalWrite(IN4, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN1, LOW);
break;
case 5:
digitalWrite(IN4, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN1, LOW);
break;
case 6:
digitalWrite(IN4, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN1, LOW);
break;
case 7:
digitalWrite(IN4, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN1, HIGH);
break;
default:
digitalWrite(IN4, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN1, HIGH);
break;
}

if(dir){
_step++;
}else{
_step--;
}
if(_step>7){
_step=0;
}
if(_step<0){
_step=7;
}

delay(1);

}
void do_nothing()
{
Serial.print("pause");
}

void setup()
{

pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4,OUTPUT);

Serial.begin(9600);

button = 31; //whatever pin your button is plugged into
pinMode(button, INPUT);
attachInterrupt(digitalPinToInterrupt(18),clockwise_manual,LOW);
attachInterrupt(digitalPinToInterrupt(19),anticlockwise_manual,LOW);
lcd.begin(16,2);
lcd.print("System on!");

}

void loop()
{

int LDRstate=digitalRead(LDR);

if(LDRstate==LOW)

{
anticlockwise;
}

if(LDRstate==HIGH)
{

clockwise();
}

if (button==HIGH)
{
flag= !flag;
}

while (flag == true)
{
do_nothing();
}

}

void clockwise_manual()
{
anticlockwise();
}
void anticlockwise_manual()
{
clockwise();

}

it doesnot work....

hahala1993:
it doesnot work....

What does that mean?

(Code tags. Mmmm yeah, we love code tags)

i mean what dorvakta taught me just now....still cnt control the void loop... bro... any solution?

 if(LDRstate==LOW)

{
 anticlockwise;
}

What's that?

"bro"?

 button = 31;
if (button==HIGH)

Doesn't seem likely, does it?

Please edit your post and use code tags

[code] your code here [/code]

will result in

your code here

Also, please be more clear with regards to 'it does not work'. I guess it blew up your Arduino? Or something else?

LDR is my light sensor(digital output)
when it become 0.. then my motor turn by anticlockwise

button=31;// my digital pin on arduino mega 2560.

if(button==HIGH) // im already try it if(button==LOW) ....but still cnt solve my problem...

LDR is my light sensor(digital output)
when it become 0.. then my motor turn by anticlockwise

But that's only if you call the function "anticlockwise", something you're not doing there, which is why I asked the question.

"HIGH" has the value 1 and "LOW" has the value 0. Neither is ever going to be equal to 31.
You need to read the condition present on pin 31 and comape that to HIGH or LOW.

im already mention pin31 as input...
yup....i call the function if my LDR goes to LOW
is it related to how to control the void loop by pressing button?

im already mention pin31 as input...

But you have to read it.

yup....i call the function if my LDR goes to LOW

Not in the code you posted you don't, which is why I pointed it out.

Use code tags as mentioned and don't cross-post.

Using a button does not need a interrupt.

Here is a button Handling code:

const byte button = 2;   // button connected: pin->button->ground

void setup()
{
  pinMode (button, INPUT_PULLUP); // enable internal pull up resistor
}

void loop()
{
  byte buttonState = buttonCheck();   // checks button
  if (buttonState == 1)
  {
    // button has been pressed
    // Do stuff here
  }
}

byte buttonCheck()   // Return positive Once per button press
{
  static int isButtonPressed;
  static byte buttonHasBeenPressed;

  if (digitalRead(button) == LOW)       // Read button on pin 2
  {
    isButtonPressed++;            // Increment Debounce variable
  }
  else
  {
    isButtonPressed = 0;          // Reset if it bounced
    buttonHasBeenPressed = 0;     // reset to 0 if button is released
  }

  if (isButtonPressed == 10 && buttonHasBeenPressed == 0)       // Debounce Confirmed Threshold
  {
    buttonHasBeenPressed = 1;     // indicates that button has been pressed
    return 1;                     // Button Pressed
  }
  else
  {
    return 0;                     // Button Not Pressed
  }
}
 Serial.begin(9600);  
 
 button = 31; //whatever pin your button is plugged into
  pinMode(button, INPUT);

...i already declared it as input...

...i already declared it as input...

But you're not reading it

my program already can work with the hardware...
now my problem just want to know how to on/off the void loop by pressing button..

OK, post your corrected code, in code tags (very important).

Tell us what it doesn't do that you expect it to do, and also tell us what it does do that you don't expect.