Help with a simple program

CrossRoads:
Or better, use pinMode (pin2, INPUT_MODE);

I'm pretty sure CrossRoads meant to use "INPUT_PULLUP" instead of "INPUT_MODE".

I renamed some of your variables on made some constants. Here's the first section of the code I wrote.

const int INDICATOR_LED_PIN = 3;
const int DOOR_SENSE_PIN = 2;
const int BLINK_DELAY = 1000;
const boolean OPEN = HIGH;
const boolean CLOSED = LOW;

int doorCounter = 0;
int doorState = CLOSED;
int previousDoorState;

void setup() 
{
  pinMode(INDICATOR_LED_PIN, OUTPUT);
  pinMode(DOOR_SENSE_PIN, INPUT_PULLUP);
}

void loop() 
{

  previousDoorState = doorState;
  doorState = digitalRead(DOOR_SENSE_PIN);
  if (doorState == OPEN && previousDoorState == CLOSED)
  {
    doorCounter++;
  }

  for (int i = 0; i <= doorCounter; i++)
  {
    digitalWrite(INDICATOR_LED_PIN, HIGH);
    delay(BLINK_DELAY);
    digitalWrite(INDICATOR_LED_PIN, LOW);
    delay(BLINK_DELAY);
  }

  delay(3000);
}

I didn't want to spoil your fun too much so I'll didn't copy the rest of the code.

Hopefully the above will get you a little further along your way.

Edit: I added the rest of the untested code.

Thanks for the help. I wish I could say this is fun but I have a permanent red spot on my forehead from banging it on the table in frustration. I'm close to giving up but knowing that this is something for christmas is keeping me going a little longer.

I added the rest of the code. The rest of the code is pretty much the same code you were using.

Make sure you follow CrossRoad's advice about how to wire the switch.

The code compiles but I haven't tested it.

The three second delay is very awkward. The code won't detect changes in door state during the delays.

lol, now I'm even more confused. So I made the changes and I added the code that you gave me but now it blinks twice and pauses right after start up and doesn't change at all based on the door opening. I may have to start from scratch. I seriously that this was an easy thing and that I was just an idiot lol.

This is the version that without delay function

int indicate = 3;
int inputPin = 2;
int x = 0;

// Variables will change :
int ledState = LOW;             // ledState used to set the LED
int longDelay =0;				// long delay state

// 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 previousMillis = 0;        // will store last time LED was updated
unsigned long previousMillis2 = 0;        // will store last time long delay was updated

// constants won't change :
const long interval = 300;           // interval at which to blink (milliseconds)
const long interval2 = 4000;           // interval at which to long delay (milliseconds)

void setup() {
  pinMode(indicate, OUTPUT);
  pinMode(inputPin, INPUT_PULLUP);

}

boolean lastButton = LOW;
boolean currentButton = LOW;

boolean debounce(boolean last)
{
  boolean current = digitalRead(inputPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(inputPin);
  }
  return current;
}

int i=0;
unsigned long currentMillis2;
void loop() {

  currentButton = debounce(lastButton);
  if (lastButton == HIGH && currentButton == LOW)
  {
    x = x+1;
  }
  lastButton = currentButton;
  
  unsigned long currentMillis = millis();



  if (x > 0 && !longDelay) {
    if (currentMillis - previousMillis >= interval) {
      // save the last time you blinked the LED
      previousMillis = currentMillis;

      // if the LED is off turn it on and vice-versa:
      if (ledState == LOW) {
        ledState = HIGH;
      } 
      else {
        ledState = LOW;
        i++;
      }

      // set the LED with the ledState of the variable:

      digitalWrite(indicate, ledState);
      if (ledState == LOW && i >= x) {
        i = 0 ;
        longDelay = 1; // done flash 
        previousMillis2 = millis(); // long delay time start now
      }
    }
  }
  
   currentMillis2 = millis();
  if (currentMillis2 - previousMillis2 >= interval2) {
    // save the last time your long delay
    previousMillis2 = currentMillis2;
    longDelay = 0;
  }
}

Hi
Can you show us a picture of your project, so we can see your layout please..

Thanks... Tom.... :slight_smile:

OMG, Bill, you did it!!! That works!! thank you so much and thanks to everyone for the help. I'm going to do my best to learn as much as possible so that I can try being an active member on this site.