Time Glove help (strobe light)

Hi all,
I'm working with my son on a school project. He's doing a research project on the history of coding, and we are working on building this project:

I have the tools and knowledge to build the circuits, but my coding is VERY basic (see what I did there?!). Anyway, I have it to where the led will flash maybe once or twice if I shake the system, but it won't continue flashing. The more I shake it, the more it flashes, but as soon as I stop moving it, the flashing stops. Except for the occasional time when the LED will stay on steady until I move again. I'm hoping maybe one of you can help me troubleshoot it. I'm running the system off a 12V battery, and using a slightly different buck boost convertor to get 30VDC to the LED, but otherwise it's identical to the system in the link. I'm trying to learn the code as much as possible, but this one is way beyond me at the moment. SO, can anyone help me with troubleshooting? I'm sort of wondering why the accelerometer is only connected to 4 pins, but assuming the wiring diagram is correct.
Thanks!

int light = 200;      // LIGHTS ON delay, microseconds
int dark;             // LIGHTS OFF delay
int min_dark = 1;     // min dark delay
int max_dark = 50;    // max dark delay
#define light_pin 2   // MOSFET pin
#define  potent_pin 6 // potentiometer pin
int angle;
boolean flag;
long lastchange;

#include <Wire.h>
#include "Kalman.h"
Kalman kalmanX;
Kalman kalmanZ;
uint8_t IMUAddress = 0x68;
/* IMU Data */
int16_t accX;
int16_t accY;
int16_t accZ;
int16_t tempRaw;
int16_t gyroX;
int16_t gyroY;
int16_t gyroZ;
double accXangle; // Angle calculate using the accelerometer
double accZangle;
double temp;
double gyroXangle = 180; // Angle calculate using the gyro
double gyroZangle = 180;
double compAngleX = 180; // Calculate the angle using a Kalman filter
double compAngleZ = 180;
double kalAngleX; // Calculate the angle using a Kalman filter
double kalAngleZ;
uint32_t timer;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  pinMode(light_pin, OUTPUT);
  i2cWrite(0x6B, 0x00); // Disable sleep mode
  kalmanX.setAngle(180); // Set starting angle
  kalmanZ.setAngle(180);
  timer = micros();
}

void loop() {
  measure();                                            // obtain acceleration and angle speeds
  if (accZ > 25000 && (millis() - lastchange > 300)) {  // Z axis shake detection
    flag = !flag;                                       // toggle light
    lastchange = millis();                              // timer
  }

  if (flag == 1) {
    angle = 250 - kalAngleZ;   // calculate angle (with 250 degrees offset)
    
    // dark times calculation
    dark = map(analogRead(potent_pin), 0, 1024, min_dark, max_dark);
    digitalWrite(light_pin, 1);    // lights up
    delayMicroseconds(light);      // wait
    digitalWrite(light_pin, 0);    // lights down
    delay(dark);                   // wait
    delayMicroseconds(2000 + angle * 10); // extra wait
  }
}

// oh my god, it's some tricky sh*t
void measure() {
  uint8_t* data = i2cRead(0x3B, 14);
  accX = ((data[0] << 8) | data[1]);
  accY = ((data[2] << 8) | data[3]);
  accZ = ((data[4] << 8) | data[5]);
  tempRaw = ((data[6] << 8) | data[7]);
  gyroX = ((data[8] << 8) | data[9]);
  gyroY = ((data[10] << 8) | data[11]);
  gyroZ = ((data[12] << 8) | data[13]);
  /* Calculate the angls based on the different sensors and algorithm */
  accZangle = (atan2(accX, accY) + PI) * RAD_TO_DEG;
  accXangle = (atan2(accY, accX) + PI) * RAD_TO_DEG;
  double gyroXrate = (double)gyroX / 131.0;
  double gyroZrate = -((double)gyroZ / 131.0);
  gyroXangle += kalmanX.getRate() * ((double)(micros() - timer) / 1000000); // Calculate gyro angle using the unbiased rate
  gyroZangle += kalmanZ.getRate() * ((double)(micros() - timer) / 1000000);
  kalAngleX = kalmanX.getAngle(accXangle, gyroXrate, (double)(micros() - timer) / 1000000); // Calculate the angle using a Kalman filter
  kalAngleZ = kalmanZ.getAngle(accZangle, gyroZrate, (double)(micros() - timer) / 1000000);
  timer = micros();
}

void i2cWrite(uint8_t registerAddress, uint8_t data) {
  Wire.beginTransmission(IMUAddress);
  Wire.write(registerAddress);
  Wire.write(data);
  Wire.endTransmission(); // Send stop
}
uint8_t* i2cRead(uint8_t registerAddress, uint8_t nbytes) {
  uint8_t data[nbytes];
  Wire.beginTransmission(IMUAddress);
  Wire.write(registerAddress);
  Wire.endTransmission(false); // Don't release the bus
  Wire.requestFrom(IMUAddress, nbytes); // Send a repeated start and then release the bus after reading
  for (uint8_t i = 0; i < nbytes; i++)
    data [i] = Wire.read();
  return data;
}
#define light_pin 2   // MOSFET pin

If you used meaningful names, the contradictory comments wouldn't be needed.

    lastchange = millis();                              // timer

A time is NOT a timer!

Regardless of what else is going on, you are going to be dark 1000 times as long as you are light. Does that make sense?

What do your Serial.print()s tell you is happening?

I'm sort of wondering why the accelerometer is only connected to 4 pins

How many pins do you expect it to be connected to? Power, ground, and the 2 I2C pins is all that I expect.

Thanks for the input. To be clear: I didn't write the code. It was copy/pasted into the IDE from the website.

I'm already lost in your replies.
The //timer line is not a timer. OK, got it. But what is it doing? Dark 1000 times longer I understand. Can you point me to the line in the code that does that?

Serial.print()....I don't see that in the code. Are you asking what it outputs back to the computer? It is not connected to the computer when running. I have a little 6" cable for programming, but it's not used to power the board in operation.

I'm completely unfamiliar with the accelerometer, I was just wondering why the other pins exist if not needed.

I can post the code for the Kalman.h library if that would be helpful. It too was copy/pasted from the website.

I'm completely unfamiliar with the accelerometer

No point in continuing until you become familiar with it. And forget the "Kalman.h" library -- it is wrong and wastes time, memory and effort. In fact, much of the code you have posted is simply wrong, but somehow manages to work "a little bit".

We recommend that Arduino beginners start small: learn to blink an LED, monitor a pushbutton, read a voltage, etc. so that you become familiar with the language and special features of the Arduino. There are tutorials on line for all of these, and accelerometers too.

Put the small bits that you understand together into a larger project.

Otherwise, be prepared for endless frustration.

But what is it doing?

It is recording when some event happened.

Dark 1000 times longer I understand. Can you point me to the line in the code that does that?

delayMicroseconds() is used between turning the light on and turning it off. delay() is used between turning it off and turning it on.

delay() wastes 1000 times as much time as delayMicroseconds(), because delay() wastes milliseconds, which are 1000 times longer than microseconds.

Serial.print()....I don't see that in the code.

Of course you don't. So, you are debugging by guessing, which is orders of magnitude more difficult than debugging with facts at hand. So, add some Serial.print() statements, to print interesting stuff. Obviously, the key is to determine what is interesting, and what isn't.

It is not connected to the computer when running.

You WILL need to connect it, until you know what is wrong with the code.

I was just wondering why the other pins exist if not needed.

You'd need to post a link to the accelerometer you are using. The other pins may not be used, except for soldering the accelerometer to a circuit board, or they may be used as SPI pins or analog pins, depending on how you choose to communicate with the device.