Modified BlinkWithoutDelay sketch

I’m working on a puzzle room/escape room game. Within the project will be a blinking light that is showing a morse code message. I am having trouble with actually making the LED blink.

Is there anywhere obvious that I am going wrong?

//#include <Key.h>
#include <Keypad.h>
#include <Arduino.h>

//        //        MORSE CODE      //        //  Pin 0   // code is 3742

    //CHOOSE PIN HERE
const int MorseledPin = 0;// the number of the LED pin
    //CHOOSE PIN HERE
int MorseLEDstate = LOW;               // MorseLED_state used to set the LED
    //Generally, you should use "unsigned long" for variables that hold time
    // The value will quickly become too large for an int to store
unsigned long MorsepreviousMillis = 0;        // will store last time LED was updated
      const int morseArrayLength = 42;        // stores the length of the array, this will cycle through to have uniqu ON/OFF time for the LED
long Morseinterval[morseArrayLength] =        // interval at which to blink (milliseconds)
    //500=dot. 1000=dash/pause
{ 1000,    //LED starts OFF-1 second pause
  500,  1000, 500,  1000, 500,  1000, 1000, 1000, 1000, 1000, //3  ...--
  1000, 1000, 1000, 1000, 500,  1000, 500,  1000, 500,  1000, //7  --...
  500,  1000, 500,  1000, 500,  1000, 500,  1000, 1000, 1000, //4  ....-
  500,  1000, 500,  1000, 1000, 1000, 1000, 1000, 1000, 1000, //2  ..---
  2000
};    //2 second pause before loop repeats
//ARRAY Starts with 'wait', step time on, then time off--use an even number of array elements to enusre consistent looping

int countM = 0;// variable will count to step through the morse code loop



/*
//        //        SAFE      //      //  Pins 1&A0

const int keyedSwitch = A0;
const int solenoid = 1;

//        //      KEYPAD        //        // Pins 2-8

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad
//FINAL GAME CODE
char* finalKey = "123456";//final unlock
//FINAL GAME CODE
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

//        //      DOOR LED        //        // Pin 9



//        //      TEST LOOP       //        // Pin 13

*/

void setup() {
  // set the digital pin as output:
  //prints to serial monitor
  Serial.begin(9600);//assign to serial port 9600 (monitor default)
  Serial.println("Hello, world");//first print at initalization
  Serial.println("");

  pinMode(MorseledPin, OUTPUT);

  // FOR FUTURE SECTIONS OF THE SKETCH  //
  //pinMode( , OUTPUT); //Solenoid
  //pinMode( , INPUT);  //
  //pinMode( , OUTPUT); //Door LED Tape
  
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  //        //        MORSE CODE        //        //
  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long MorsecurrentMillis = millis();

  //Serial.print("MorseledPin=");
  //Serial.println(MorseledPin);
  //Serial.print("countM=" );
  //Serial.println(countM);

  if (MorsecurrentMillis - MorsepreviousMillis >= Morseinterval[countM]) { // save the last time you blinked the LED
    MorsepreviousMillis = MorsecurrentMillis;

    // if the LED is off turn it on and vice-versa:
    if (MorseLEDstate == LOW) {
      MorseLEDstate = HIGH;
      countM = countM + 1; //step forward in array 'morse'
      Serial.println("MorseLEDstate=HIGH");
      Serial.print("MorseledPin=");
      Serial.println(MorseledPin);
      Serial.print("countM=" );
      Serial.println(countM);
    } else {
      MorseLEDstate = LOW;
      countM = countM + 1;
      Serial.println("MorseLEDstate=LOW");
      Serial.print("MorseledPin=");
      Serial.println(MorseledPin);
      Serial.print("countM=" );
      Serial.println(countM);
    }
    digitalWrite(MorseledPin, MorseLEDstate);//set the LED pin to the current LED state
    /*
    if (countM == morseArrayLength - 1)
    {
      countM = 0;//resets count-the morse code will loop
    }
    */
  }
}

Escape_Room_Master-In_Progress.ino (3.98 KB)

Can you do two things for us:

  1. Describe the problem. You haven't really given us any symptoms. What does this code do or not do that is contrary to what you expect.

  2. Please remove all the commented out code and format what is left (control-T in the IDE) to make it readable. It's really hard to look at right now.