code stopps after using a function

Hi!
I got a problem with my code and obviously I made a mistake which I cannot find. Maybe someone here can help me out!?
My code is running well but at the point when the parameter"section" turns from 0 to 1 in the function “STOP()” it seems like the code just stops to work. I’ve tried to figure out this by using Serial.print() as you can see …

I put the code right here and also as an attachment … hopefully someone can see the problem

#include <Servo.h>

Servo MotX; // Antrieb in X → XV und XR
Servo MotY; // Antrieb in Y → YV und YR

const int stateLedPin = 12; // status led (on button)
// blink variables
int stateLedState = LOW; // variable for blink function
long previousMillis = 0;
unsigned long currentMillis = 0;
long intervalFast = 500;
long intervalSlow = 1000;

const int buttonPin = 8; // startbutton
int buttonState = HIGH;
const int buzzerPin = 7; // pin for piezo buzzer

const int XsensPin = 2; // Hallswitch X-direction
const int YsensPin = 3; // Hallswitch Y-direction

int goSTOP = 1500;
int go = 0;
int goXV = 1350;
int goXR = 1600;
int goYV = 1350;
int goYR = 1600;
int goDelay = 15; // Verzögerung für sanften Anlauf
int section = 10; // section index: 0 for fist movement, 9 for last one,
// 10 for resting position

boolean goXstate = LOW;
boolean goYstate = LOW;
boolean waiting = LOW;
boolean lockState = LOW; // status of container lock

void setup()
{
Serial.begin(9600);
attachInterrupt(0, STOP, FALLING); // interrupt Y-direction (Pin 2)
attachInterrupt(1, STOP, FALLING); // interrupt X-direction (Pin 3)
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
pinMode(stateLedPin, OUTPUT);
digitalWrite(stateLedPin, HIGH);
//MotX.attach(5);
//MotY.attach(6);
//MotX.writeMicroseconds(1500); // Regler X auf “0” justieren
//MotY.writeMicroseconds(1500); // Regler Y auf “0” justieren
// just for test -------
analogWrite(5, 100);
analogWrite(6, 100);
//----------------------
delay(1000); // set on 5000 !!!
// just for test -------
analogWrite(5, 0);
analogWrite(6, 0);
//----------------------
beep(50);
beep(50);
beep(50);
delay(500);
digitalWrite(stateLedPin, LOW);

}

void loop()
{
Serial.println(“loop”);
switch(section)
{
case 0:

Serial.println(“section 0”);
//MotY.writeMicroseconds(goYV);
// just for test--------
analogWrite(5, 100);
//----------------------
goYstate = HIGH;
delay(1000);
while(goYstate == HIGH)
{
// just wait for the interrupt
}

case 1:

Serial.println(“section 1”);
//MotX.writeMicroseconds(goXV);
// just for test--------
analogWrite(6, 100);
//----------------------
goXstate = HIGH;
delay(1000);
while(goXstate == HIGH)
{
// just wait for the interrupt
}

case 2:

Serial.println(“section 2”);

/*

*/

case 10:

Serial.println(“last block”);
while(section == 10)
{
BLINKfast();
buttonState = digitalRead(buttonPin);
if(buttonState == LOW)
{
section = 0; // no longer waiting → begin section countdigitalWrite(stateLedPin, LOW);
digitalWrite(stateLedPin, LOW);
}
}
}
}

//=========== FUNCTIONS ====================

// -----------------------------------------
void XV()
{
for(go = 0; go <= goXV; go += 10)
{
MotX.writeMicroseconds(go);
delay(goDelay);
}
}
// -----------------------------------------
void XR()
{
for(go = 0; go <= goXR; go += 10)
{
MotX.writeMicroseconds(go);
delay(goDelay);
}
}
// -----------------------------------------
void YV()
{
for(go = 0; go <= goYV; go += 10)
{
MotY.writeMicroseconds(go);
delay(goDelay);
}
}
// -----------------------------------------
void YR()
{
for(go = 0; go <= goYR; go += 10)
{
MotY.writeMicroseconds(go);
delay(goDelay);
}
}
// -----------------------------------------
int BLINKfast()
{
currentMillis = millis();
if(currentMillis - previousMillis > intervalFast)
{
previousMillis = currentMillis;
if (stateLedState == LOW)
{
stateLedState = HIGH;
}
else
{
stateLedState = LOW;
}
digitalWrite(stateLedPin, stateLedState);
}
}
// -----------------------------------------
int BLINKslow()
{
currentMillis = millis();
if(currentMillis - previousMillis > intervalSlow)
{
previousMillis = currentMillis;
if (stateLedState == LOW)
{
stateLedState = HIGH;
}
else
{
stateLedState = LOW;
}
digitalWrite(stateLedPin, stateLedState);
}
}
// -----------------------------------------
void beep(unsigned char delayms)
{
digitalWrite(buzzerPin, HIGH);
delay(delayms);
digitalWrite(buzzerPin, LOW);
delay(delayms);
}
// -----------------------------------------
void STOP()
{
Serial.println(“STOP”);
//MotX.writeMicroseconds(goSTOP);
//MotY.writeMicroseconds(goSTOP);
// just for test -------
analogWrite(5, 0);
analogWrite(6, 0);
//----------------------
goXstate = LOW;
goYstate = LOW;
section++;
Serial.print("section: ");
Serial.println(section);
}

CL_051.ino (4.86 KB)

Serial.print in interrupt context?

"section" should be qualified "volatile".

Please, please, please use code tags when posting code.

i'm not sure what you want to know... i just used serial.print to see untill which point my code works

You shouldn't be using it in an interrupt

THANK YOU!!! the failure was that I used int section; instead of volatile int section;

click the MODIFY button in the upper right of the post window. Highlight all you code. click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button. click SAVE (at the bottom). When you post code on the forum, please make a habit of using the code tags "#" button.