Hello all, does anyone have any advice in adding two pieces of code together? Im very new to coding, and Im working on a school project. The 2 pieces of code work separately, but I need to implement them together to make a project work. I have a one-wire input 4x4 keypad that I am trying to use as a security code to turn a servo to open a door.
Here is that code:
String keys="123A456B789C*0#D";
int key;
boolean key_lockout=false;
void setup(){
Serial.begin(9600);
}
void loop(){
key=getKeypad();
if(key!=-1)
Serial.println(keys[key]);
delay(10);
}
int getKeypad(){
int ret=-1;
boolean reset_lockout=false;
if(analogRead(A0)==0)
key_lockout=false;
else if(!key_lockout){
delay(20);
ret=15-(log((analogRead(A0)-183.9)/58.24)/0.1623)+0.5;
key_lockout=true;
}
return ret;
}
Then, I have a bush-button release code to operate the door from the inside, that code is:
#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
int pos = 90;
Servo servo1;
void setup()
{
pinMode(button1, INPUT);
servo1.attach(13);
digitalWrite(4, HIGH); //enable pullups to make pin high
}
void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{
servo1.write(0);
delay(5000);
servo1.write(90);
}
}
Any advice? I know I need to add a "password detect" piece of coded, but I am not sure how. Any advice would be awesome. Thank you.