Sorry I’ll post all the code. I’m using the GLCD library and the Keypad library. I have rejigged it since the last post, I’ve unplugged pins 0 and 1 for diagnostics and currently have 4 wires in, for 3 rows and 1 column on the keypad.
Yes unfortunately I have used all the pins. I’m even sharing analog 5 as a digital on 19 and an A5. Luckily I’ve made this a condition so they don’t conflict.
I hope you can help!
// -------------------------------------------------------------------------------------------------------INITIALISE---------------------------------------------------------
#include <glcd.h>
#include <Keypad.h>
#include <Servo.h>
#include "fonts/Arial14.h" // proportional font
#include "fonts/SystemFont5x7.h" // system font
#include "bitmaps/allBitmaps.h"
const byte myRows = 3; // number of rows
const byte myCols = 1; //number of columns
Servo myservo;
char keys[myRows][myCols] = {
{'1'},
{'4'},
{'7'}
}; //character array to map the button layout of the keypad
byte rowPins[myRows] = {13, 12, 3}; //array to map keypad to MCU pins
byte colPins[myCols] = {2}; //array to map keypad to MCU pins
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, myRows, myCols ); //keypad library map function
char inputArray[4]; //array to gather user keypad presses
char Main[4] = {'1','4','7','1'}; //array to hold keypad password
int i = 0;
int state = 1; //Creates the state
int pos = 0; // servo position
unsigned long startMillis;
unsigned int loops = 0;
unsigned int iter = 0;
// --------------------------------------------------------------------------------------------------------------SETUP---------------------------------------------------------
void setup(){
GLCD.Init(NON_INVERTED); // initialise the library, non inverted writes pixels onto a clear screen
GLCD.ClearScreen();
GLCD.SelectFont(System5x7); // switch to fixed width system font
GLCD.ClearScreen();
GLCD.DrawBitmap(splash1, 0,0, BLACK);
delay(1000);
GLCD.ClearScreen();
GLCD.DrawBitmap(splash2, 0,0, BLACK);
delay(500);
GLCD.ClearScreen();
GLCD.DrawBitmap(splash3, 0,0, BLACK);
delay(500);
GLCD.ClearScreen();
GLCD.DrawBitmap(splash4, 0,0, BLACK);
delay(500);
GLCD.ClearScreen();
GLCD.DrawBitmap(splash1, 0,0, BLACK);
delay(500);
GLCD.ClearScreen();
GLCD.DrawBitmap(splash2, 0,0, BLACK);
delay(500);
GLCD.ClearScreen();
GLCD.DrawBitmap(splash3, 0,0, BLACK);
delay(1000);
GLCD.ClearScreen();
GLCD.DrawBitmap(splash4, 0,0, BLACK);
delay(500);
GLCD.ClearScreen();
GLCD.DrawBitmap(splash5, 0,0, BLACK);
delay(4000);
GLCD.ClearScreen(); // clear the screen
}
// --------------------------------------------------------------------------------------------------------------LOOP---------------------------------------------------------
void loop()
{
waiting();
}
// -------------------------------------------------------------------------------------------------CORRECT PIN ENTERED---------------------------------------------------------
void correctpin()
{
myservo.attach(19);
GLCD.DrawBitmap(welcome, 0,0, BLACK);
GLCD.CursorToXY(69,27);
GLCD.print("Tom");
delay(2000);
GLCD.ClearScreen();
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 90 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(5000);
for(pos = 90; pos>=1; pos-=1) // goes from 90 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
loop();
}
// --------------------------------------------------------------------------------------------INCORRECT PIN ENTERED---------------------------------------------------------
void incorrectpin()
{
GLCD.DrawBitmap(incorrect, 0,0, BLACK);
delay(4000);
GLCD.ClearScreen();
pincode();
}
// ------------------------------------------------------------------------------------------------READ FROM KEYPAD---------------------------------------------------------
void pincode()
{
Serial.begin(9600);
GLCD.DrawBitmap(pin, 0,0, BLACK);
char key= kpd.getKey();
Serial.print(key);
{
inputArray[i] = key; // store's key entry
i++;
if (i == 1) //if 1 press has been made
{
GLCD.DrawBitmap(pin1, 0,0, BLACK);
}
if (i == 2) //if 2 presses have been made
{
GLCD.DrawBitmap(pin2, 0,0, BLACK);
}
if (i == 3) //if 3 presses have been made
{
GLCD.DrawBitmap(pin3, 0,0, BLACK);
}
if (i == 4) //if 4 presses have been made
{
GLCD.DrawBitmap(pin4, 0,0, BLACK);
{
delay(5000);
if (inputArray[0] == Main[0] &&
inputArray[1] == Main[1] &&
inputArray[2] == Main[2] &&
inputArray[3] == Main[3])
{
correctpin();
}
else
{
incorrectpin();
}
}
{
i=0; // reset integer to store user keypresses
}
}
}
}
// ----------------------------------------------------------------------------WAITING FOR RFID---------------------------------------------------------
void waiting()
{
int RFID = analogRead(A5);
RFID = map(RFID, 0, 1023, 0, 5);
GLCD.DrawBitmap(waiting1, 0,0, BLACK);
delay(500);
GLCD.DrawBitmap(waiting2, 0,0, BLACK);
delay(500);
if (RFID < 2) // CODE FOR RFID ANALOG VALUE. NEEDS TWEAKING
{
GLCD.ClearScreen();
pincode();
}
else
{
GLCD.ClearScreen();
loop();
}
}