Alright i have read how to post and i will give it a shot. I'm sure there is a better way to code it but i found this the simplest way, any suggestions welcome.
Thank You
#include "Keypad.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,16,2); // set the LCD address to 0x20 for a 16 chars and 2 line display
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] = {
5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
8, 7, 6}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char RED[2]={
'1','2'}; // our secret (!) number
char YELLOW[2]={
'2','3'}; //YELLOW now
char BLUE[2]={
'4','2'};
char attemptC[2]={
0,0}; // used for comparison
char GREEN[2]={
'1','3'};
int z=0;
int ledRed = 12;
int ledYellow = 11;
int ledGreen = 10;
int ledOrange = 13;
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight(); //turns backlight on
lcd.print("Pick Your Color");
pinMode(ledRed, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledOrange, OUTPUT);
incorrectPIN();
}
void optionOne(){
lcd.clear();
lcd.print("Super Epic!");
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, HIGH);
delay(2000);
incorrectPIN();
}
void GREENS(){
lcd.clear();
lcd.print("EPIC!");
digitalWrite(ledRed, LOW);
digitalWrite(ledOrange, HIGH);
delay(2000);
digitalWrite(ledOrange, LOW);
incorrectPIN();
}
void correctPIN() // do this if correct PIN entered
{
lcd.clear();
lcd.print("Hip hip Hooray!");
digitalWrite(ledRed, LOW);
digitalWrite(ledYellow, HIGH);
delay(3000);
incorrectPIN();
}
void incorrectPIN() // do this if incorrect PIN entered
{
lcd.clear();
lcd.print("Pick Your Color");
digitalWrite(ledGreen, LOW);
digitalWrite(ledRed, HIGH);
digitalWrite(ledYellow, LOW);
}
void optionTwo(){
lcd.clear();
lcd.print("It Works");
digitalWrite(ledRed, LOW);
for(int x=0; x<10; x++){
digitalWrite(ledYellow, HIGH);
delay(250);
digitalWrite(ledYellow, LOW);
delay(250);
}
incorrectPIN();
}
void checkPIN()
{
if (attemptC[0]==RED[0]&&
attemptC[1]==RED[1])
{
correctPIN();
}
else
{
incorrectPIN();
}
if (attemptC[0]==YELLOW[0]&&
attemptC[1]==YELLOW[1])
{
optionOne();
}
else
{
incorrectPIN();
}
if (attemptC[0]==BLUE[0]&&
attemptC[1]==BLUE[1])
{
optionTwo();
}
else
{
incorrectPIN();
}
if (attemptC[0]==GREEN[0]&&
attemptC[1]==GREEN[1])
{
GREENS();
}
else
{
incorrectPIN();
}
for (int zz=0; zz<6; zz++) // wipe attempt
{
attemptC[zz]=0;
}
}
void readKeypad()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
switch(key)
{
case '*':
z=0;
break;
case '#':
delay(100); // for extra debounce
checkPIN();
break;
default:
attemptC[z]=key;
z++;
}
}
}
void loop()
{
readKeypad();
}