Joining two sketches together

I know this will be easy for some, but I am getting more and more in a muddle here.
I have two working sketches (sketch 1 is a RFID reader)(sketch 2 is the alarm setting and monitoring)
When I try merge the two sketches, they compile, but all I seem to have working is the RFID reader, and not the setting and monitoring.
Rather than having two arduinos running, how can I merge onto one sketch?

I have been trying to get the output from the RFID part:

/////////////////////////////////////////  Access Granted    ///////////////////////////////////
void granted (int setDelay) {
  digitalWrite(blueLed, LED_OFF);   // Turn off blue LED
  digitalWrite(redLed, LED_OFF);  // Turn off red LED
  digitalWrite(greenLed, LED_ON);   // Turn on green LED
  //digitalWrite(alarmSet, LOW);     // Unlock door!
 setval = HIGH;
  delay(setDelay);          // Hold door lock open for given seconds
  //digitalWrite(alarmSet, HIGH);    // Relock door
  setval = LOW;
  delay(1000);            // Hold green LED on for a second
}

To change the "setval" of the alarm setting and monitoring part:

 if (setval == HIGH)
  {
    setreading = HIGH;
    key = 1;                              // used to detect if a  keycard has been swiped
  }
  else
  {
    setreading = LOW;
    key = 0;
  }
  if (setreading == HIGH && setprevious == LOW && millis() - time > debounce)   // next part of code is to go from a pulse to an on/off state
  {
    if (setstatus == HIGH)
      setstatus = LOW;
    else
      setstatus = HIGH;
    time = millis();
  }
  setprevious = setreading;

I have had to attach the files below due to size.

RFID.txt (19.8 KB)

alarm setting and monitor.txt (11 KB)

What I have so far.txt (29.4 KB)

Delete everything from granted() that has nothing to do with setval, and you have:

void granted (int setDelay) {
  setval = HIGH;
  setval = LOW;
}

It is hard to imagine how you expect setval to be anything other than LOW when the function ends.

PaulS:
Delete everything from granted() that has nothing to do with setval, and you have:

void granted (int setDelay) {

setval = HIGH;
 setval = LOW;
}




It is hard to imagine how you expect setval to be anything other than LOW when the function ends.

I have changed it like you suggested

void granted (int setDelay) {
  digitalWrite(blueLed, LED_OFF);   // Turn off blue LED
  digitalWrite(redLed, LED_OFF);  // Turn off red LED
  digitalWrite(greenLed, LED_ON);   // Turn on green LED
  setval = HIGH;
   
}

It now changes the LCD to say "Keycard Recognized", but that's as far as it goes???

I have changed it like you suggested

I did NOT suggest that. I was simply questioning why you expected the value to be anything other than LOW.

The name, setval, does NOT mean a thing. The value in setval is not used in the function that assigns it a value, SO THAT FUNCTION SHOULD NOT BE ASSIGNING IT TWO DIFFERENT VALUES.

"but that's as far as it goes???" doesn't mean anything, either. The code does something. You MUST explain what it does. You expect it to do something. You MUST explain what you expect.

I wonder if this Simple Merge Demo may help.

It does its best to keep the code from the two programs separate. However you do need to ensure there is no clash of variable names or attempts to use something (such as an I/O pin) twice.

...R

Okay still lost on this one.

The code for the RFID:-
When a recognised RFID tag is scanned, it currently puts a LED on pin 7 High.

The code for the alarm setting & monitoring :-
-When it receives an input at pin 2, it set the countdown to give you chance to get out the building.
-After the countdown it is then "set", if it detects a signal from the PIR's on pin 4, it then starts a countdown to give you chance to disable it (again pushing the button on pin 2)
-If it is not reset, it will activate the alarm siren.

I would like to merge the two so that:-

When a recognised RFID tag it put an signal out that so it can be read like the input from pin 2.

All I have as yet is it recognises the RFID tags, and it will change the LCD to read "KEYCARD RECOGNIZED", but it won't start the countdown to set the alarm ect.

I do apologize as I am new to this, I'm not the most clever guy in the class, but this is a fun hobby that I'm struggling to understand always.

Cbrenn0823:
Okay still lost on this one.

Assuming you have been updating your program taking account of comments here you need to post your latest code.

...R