Sorry if i wasn't being clear but I have the code working with the keypad library just how i want now i need it to work with the serial encoder so I can free up six extra pins ill include the code that worked with the keypad library so you can see just how i used it.
#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 TEST[]= "12"; // number combination for test
char SECOND[]= "13"; //nubmer combinatinon for second
char THIRD[]= "14"; //number combination for third
char FOURTH[]= "15"; // number combination for fourth
char attemptC[3]={
0,0,0}; // array where the attempt is strored and compared to what is entered
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
pinMode(ledRed, OUTPUT);
pinMode(ledYellow, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledOrange, OUTPUT);
incorrectPIN();
}
void functionOne(){
lcd.clear();
lcd.print("working");
lcd.setCursor(0,1);
lcd.print("hard!");
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, HIGH);
delay(2000);
incorrectPIN();
}
void functionTwo(){
lcd.clear();
lcd.print("working");
lcd.setCursor(0,1);
lcd.print("hard!");
digitalWrite(ledRed, LOW);
digitalWrite(ledOrange, HIGH);
delay(2000);
digitalWrite(ledOrange, LOW);
incorrectPIN();
}
void functionThree() // do this if correct PIN entered
{
lcd.clear();
lcd.print("working");
lcd.setCursor(0,1);
lcd.print("hard!");
digitalWrite(ledRed, LOW);
digitalWrite(ledYellow, HIGH);
delay(3000);
incorrectPIN();
}
void functionFour(){
lcd.clear();
lcd.print("working");
lcd.setCursor(0,1);
lcd.print("Hard!");
digitalWrite(ledRed, LOW);
for(int x=0; x<10; x++){
digitalWrite(ledYellow, HIGH);
delay(250);
digitalWrite(ledYellow, LOW);
delay(250);
}
incorrectPIN();
}
void incorrectPIN() // always running by default and showing on the lcd
{
lcd.clear();
lcd.print("Pick a number");
digitalWrite(ledGreen, LOW);
digitalWrite(ledRed, HIGH);
digitalWrite(ledYellow, LOW);
}
void checkPIN()
{
if(strcmp(TEST, attemptC) == 0){
functionThree();
}
{
if(strcmp(THIRD, attemptC) == 0){
functionOne();
}
}
{
if(strcmp(FOURTH, attemptC) == 0){
functionFour();
}
}
{
if(strcmp(SECOND, attemptC) == 0){
functionTwo();
}
}
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;
lcd.clear();
lcd.print("Pick a number");
break;
case '#':
delay(100); // for extra debounce
checkPIN();
break;
default:
attemptC[z]=key;
z++;
attemptC[z] = '\0';
if(strcmp(TEST, attemptC) == 0){
lcd.clear();
lcd.print("HELLO");
}
if(strcmp(THIRD, attemptC) == 0){
lcd.clear();
lcd.print("How are you?");
}
if(strcmp(FOURTH, attemptC) == 0){
lcd.clear();
lcd.print("Are you sure?");
lcd.setCursor(0,1);
lcd.print("*(Back)(Accept)#");
}
if(strcmp(SECOND, attemptC) == 0){
lcd.clear();
lcd.print("Continue?");
lcd.setCursor(0,1);
lcd.print("*(Back)(Accept)#");
}
}
}
}
void loop()
{
readKeypad();
}
I would like to be able to do this exact same this with the serial encoder but for some reason i can't figure out how to compare the strings.
Thank you for your help