Need help combining programs with a push button

From a converted Nightrider helmet sketch and one for LED state circuits by means of buttons, I have put together the following sketch attempt.

Unfortunately he does not run like that.

The main programs individually - without push-button combination - work.

It seems synonymous in both syntax syntax differences?
Can that be “harmonized”?

Unfortunately I have to get it started somehow and I’m not a programmer.
But maybe one can have a friendly-checking eye on it and help eliminate the mistakes. That would be awesome!

Sketch attempt with push button and 2 main programs to toggle:

Main program 1 (light mode 2) differs from main program 2 (light mode 3) only in the delay value (perhaps this makes it possible to simplify / shorten the overall script?).

(To the circuit: Between TasterPin 2-connection and the appropriate button feet a 10 kilo-ohm resistance is plugged in and connected to GND The other button-foot depends on 5V.)

Here my trial:


#include <Adafruit_NeoPixel.h>
#define N_LEDS 60
#define PIN     6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
const int tasterPin = 2;
int tasterStatus = LOW;
int tasterGedrueckt = 0;
int lichtmodus = 0;
int stripStatus = LOW;
int entprellZeit = 200; // debounce time
unsigned long tasterZeit = 0;

void setup()
{
int pos = 0, dir = 1;
pinMode(PIN, OUTPUT);
pinMode(tasterPin, INPUT);
strip.begin();
}

void loop()
{
tasterStatus = digitalRead(tasterPin);
if (tasterStatus == HIGH) 
{
tasterZeit = millis();
tasterGedrueckt = 1; // button pushed
} 
if ((millis() - tasterZeit > entprellZeit) && tasterGedrueckt == 1)
{
lichtmodus++;
tasterGedrueckt = 0;
}
if (lichtmodus == 0)
{
digitalWrite(PIN, LOW);
}

else if (lichtmodus == 1)
{
  int j;
int pos = 0, dir = 1;
digitalWrite(PIN, stripStatus);
  strip.setPixelColor(pos - 2, 0xFF0000);
  strip.setPixelColor(pos - 1, 0xFF0000);
  strip.setPixelColor(pos    , 0xFF0000);
  strip.setPixelColor(pos + 1, 0xFF0000);
  strip.setPixelColor(pos + 2, 0xFF0000);
  strip.show();
  delay(6);
 
  for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);

  pos += dir;
  if(pos < 0) {
    pos = 1;
    dir = -dir;
  } else if(pos >= strip.numPixels()) {
    pos = strip.numPixels() - 2;
    dir = -dir;
  }
}

else if (lichtmodus == 2)
{
digitalWrite(PIN, LOW);
}

else if (lichtmodus == 3)
{  
  int j;
int pos = 0, dir = 1;
digitalWrite(PIN, stripStatus);
  strip.setPixelColor(pos - 2, 0xFF0000);
  strip.setPixelColor(pos - 1, 0xFF0000);
  strip.setPixelColor(pos    , 0xFF0000);
  strip.setPixelColor(pos + 1, 0xFF0000);
  strip.setPixelColor(pos + 2, 0xFF0000);
  strip.show();
  delay(30);

  for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);

  pos += dir;
  if(pos < 0) {
    pos = 1;
    dir = -dir;
  } else if(pos >= strip.numPixels()) {
    pos = strip.numPixels() - 2;
    dir = -dir;
  }
}

else if (lichtmodus == 4)
{
digitalWrite(PIN, LOW);
}

else
{
lichtmodus = 0;
}
}

OK, first things first.

You need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the “More → Modify” option below the right hand corner of your post - to mark up your code as such using the “</>” icon in the posting window. Just highlight each section of code (or output) from the IDE and click the icon. In fact, the IDE has a “copy for forum” link to put these markings on a highlighted block for you so you then just paste it here in a posting window.

It is inappropriate to attach it as a “.ino” file. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

But don’t forget to use the “Auto-Format” (Ctrl-T) option first to make it easy to read. If you do not post it as “code”, it can be quite garbled and is always more difficult to read.

Also tidy up your blank space. Use blank lines only between functional blocks.

I don't think your debounce code does what it should. tasterZeit will keep being updated as long as the pin is 1, which means the entprellZeit will never elapse.

if (tasterStatus == HIGH)
{
tasterZeit = millis(); // aktualisiere tasterZeit

Try this instead:

if ((tasterStatus == HIGH) && (tasterGedrueckt == 0))
{
tasterZeit = millis(); // aktualisiere tasterZeit