Pause problem. cant undo and repeat

I need to pause my loop and when i press the same button my loop need to continue where it was. But now when i press pause i cant undo it. Any idea on how to fix it?

My Code:

#define MotorBewegenLinks 7
#define MotorBewegenRechts 8
#define Punt1 4
#define Punt2 5
#define Punt3 6
#define Start 10
#define Stop 2
#define Noodstop 3
#define Sensor 9
#define Herstel 11
#define bakopen 12
#define bakdicht 13
int stap = 0;
int status_pauze = 0;
bool edge = 1;

void setup() {

  Serial.begin(9600);

  
    pinMode(Punt1, OUTPUT);
    pinMode(Punt2, OUTPUT);
    pinMode(Punt3, OUTPUT);
    pinMode(MotorBewegenLinks, OUTPUT);
    pinMode(MotorBewegenRechts, OUTPUT);
    pinMode(Start, INPUT);
    pinMode(Stop, INPUT);
    pinMode(Noodstop, INPUT);
    pinMode(Sensor, INPUT);
    pinMode(Herstel, INPUT);
    pinMode(bakopen, OUTPUT);
    pinMode(bakdicht, OUTPUT);
    
    attachInterrupt(digitalPinToInterrupt(Stop), Pauze, RISING);
    attachInterrupt(digitalPinToInterrupt(Noodstop), noodstop, RISING);    
}

void loop() {

  if(digitalRead(Start) && digitalRead(Sensor)){
      stap = 1;
     for(int i = Punt1; i <= Punt3; i++){
      water(i);
      
     }
  }
}

void water(int punt){
  digitalWrite(MotorBewegenLinks, HIGH);
  Serial.println("Motor links aan");
  delay(1000);
  digitalWrite(MotorBewegenLinks, LOW);
  Serial.println("Motor links uit");
  delay(500);
  digitalWrite(punt, HIGH);
  Serial.println("Aangekomen bij punt");
  delay(500); 
  digitalWrite(bakopen, HIGH);
  Serial.println("Bak open");
  delay(1000);
  digitalWrite(bakopen, LOW);
  delay(500);
  digitalWrite(bakdicht, HIGH);
  Serial.println("Bak dicht");
  delay(1000);
  digitalWrite(bakdicht, LOW);
  delay(500);
  digitalWrite(punt, LOW);
  Serial.println("Weg bij punt");

  if ( punt == Punt3){
    digitalWrite(MotorBewegenRechts, HIGH);
    Serial.println("Motor terug naar begin");
    delay(3000);
    digitalWrite(MotorBewegenRechts, LOW);
    Serial.println("Motor bij begin");
  }
}

void Pauze(){
 edge = 1;
 status_pauze = !status_pauze;
 while (status_pauze = 1){
 if (digitalRead(Stop) && edge == 0){break;}
 Serial.println("Pauze hoog");
 if (digitalRead(Stop) == 0){
  Serial.println("Pauze uit");
    edge = 0;
  }
 }
}

  while (status_pauze = 1)

This is a problem but there may be others

You should not be calling loop () explicitly like this.

You should not have blocking code in interrupt context

that wasnt supposed to be there i removed it. as in i first need to have a working pause before adding a noodstop

Please post your code as it is now in a new reply here

i edited the post the code as it is now should be there

That was not what I asked you to do

What I asked was

Now, of course, comments on the original code are meaningless and you have not fixed the problem that I pointed out anyway

I dont understand sorry

You posted a sketch
Comments were made about the sketch
You say that you changed the sketch
The comments no longer make sense

The code in your original post still has at least one problem

while (status_pauze = 1)

= is used to assign a value to a variable
== is used to compare 2 variables or values

As it is, that line of code sets status_pauze to a value of 1. It does not compare it with a value of 1

You didn't declare the function 'noodstop' you call when the Noodstop pin rises.

sketch_jan06b.ino: In function 'void setup()':
sketch_jan06b:37:52: error: 'noodstop' was not declared in this scope
   attachInterrupt(digitalPinToInterrupt(Noodstop), noodstop, RISING);
                                                    ^~~~~~~~

Ty this worked

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.