Programm not Working

Hello, I am trying to programm a stop button into my project using the IOT-cloud. I have 5 Variables, the one causing issues being an bool variable called end. My code is supossed to repeat the block "prozess" after I press start. In that block I have an if statement to check if end is being pressed. The programm recognises it when I press the button before I start. Howether not when prozess has started. Does anyone know how I can fix this?

#include "thingProperties.h"

const int pressPin = 4;
const int motorPin = 3;
const int cutPin = 2;
const int pressingPin = 10;
const int cuttingPin = 9;
int mengeUbrig = 0;
int pressed = 1;


void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
  
  pinMode(motorPin, OUTPUT);
  pinMode(pressPin, OUTPUT);
  pinMode(cutPin, OUTPUT);
  pinMode(pressingPin, INPUT);
  pinMode(cuttingPin, INPUT);

  press = 1;
  start = 0;
  length = 5;
  menge = 5;
  end = 0;
}

void loop() {
  ArduinoCloud.update();

  pressed = digitalRead(pressingPin);

  mengeUbrig = 0;
      
  if(press == HIGH){
    digitalWrite(pressPin, HIGH);
  }
  
  if(press == LOW){
    digitalWrite(pressPin, LOW);
  }
  
 /* // Remove slash and asterix to print Status of A1 
 
 if(pressed == LOW){
    Serial.print("pressed = LOW");
    Serial.println();
  }
  if(pressed == HIGH){
    Serial.print("pressed = HIGH");
    Serial.println();
  }  
  */
  if(start == HIGH){
    // check if pressed
    if(pressed == LOW){
      Serial.print("Zuerst Pressen");
      Serial.println();
      }else {
      mengeUbrig = menge;
      Serial.print("Startet");
      Serial.println();
      //cut of excess
      digitalWrite(cutPin, HIGH);
      delay(150);
      digitalWrite(cutPin, LOW);
      delay(100);
      goto prozess;
      
      prozess:
      Serial.print("prozess");
      Serial.println();
      delay(100);
      //check if stop pressed
      if(end == HIGH){
        goto STOP;
      }
      if(end == LOW){
         if(mengeUbrig > 0){
           //print ammount left
            Serial.print("Litze ");
            Serial.print(menge - mengeUbrig + 1);
            Serial.print(" wird abgeschnitten");
            Serial.println();
            delay(100);
           //dispense at given length
            digitalWrite(motorPin, HIGH);
            delay(length*21.1);
            digitalWrite(motorPin, LOW);
            delay(100);
           //cut
            digitalWrite(cutPin, HIGH);
            delay(150);
            digitalWrite(cutPin, LOW);
            delay(200);
           //print amount left
            mengeUbrig = mengeUbrig - 1;
            Serial.print("Menge Übrig: ");
            Serial.print(mengeUbrig);
            Serial.println();
            delay(50);
              goto prozess;
          } else{
           //dispense an extra bit to prevent blockage
              digitalWrite(motorPin, HIGH);
              delay(30);
              digitalWrite(motorPin, LOW);
              delay(100);

            }
        //when stop pressed
          } else {
          if(end == HIGH){
            goto STOP;
            STOP:
              Serial.print("STOP");
              Serial.println();
              delay(100);
          }
          }
    }
    } else {
      delay(100);
      }
  }
  

/*
  Since Start is READ_WRITE variable, onStartChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onStartChange()  {
  // Add your code here to act upon Start change
}

/*
  Since Press is READ_WRITE variable, onPressChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onPressChange()  {
  // Add your code here to act upon Press change
}
/*
  Since Length is READ_WRITE variable, onLengthChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLengthChange()  {
  // Add your code here to act upon Length change
  Serial.print("Length set to  ");
  Serial.print(length);
  Serial.println();
}
/*
  Since Menge is READ_WRITE variable, onMengeChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onMengeChange()  {
  // Add your code here to act upon Menge change
  Serial.print("Ammount set to  ");
  Serial.print(menge);
  Serial.println();
}
/*
  Since End is READ_WRITE variable, onEndChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onEndChange()  {
  // Add your code here to act upon End change
}

Be carefull with "goto" where does the code go after that.?

I mannaged to solve by putting ArduinoCloud.update(); in the start of prozess

1 Like

So is the buttons now working?

Yeah

It works now you say. I wouldn't have thought it compiled. Do you have warnings turned on in the IDE? I also wonder if the verification would have complained about a few things.

This

            goto STOP;
            STOP:

is pointless, as is this

      goto prozess;
      
      prozess:

Some of your other uses of goto seem to want to jump into the middle of things.

There is no need, zero, it is absolutely unnecessary to use goto in your sketch. I suggest you to learn how to program without it.

a7

I thought other wise.
Does not compile and "press" is always 1.

Also UNSOLVE the solution.