Serial Keypad Encoder problems

Hello I recently purchased a Serial Keypad Encoder from electrojoystick he gives a basic code that puts the button you hit on the keyboard in the serial monitor, it looks like this.

char num; //variable num as character data type
void setup() {
Serial.begin(9600); //set baud rate to 9600
}
void loop() {
if (Serial.available() > 0) //if Serial has incoming data
{
num = Serial.read(); //store the serial data to char num
Serial.print(num); //ouput serial data to screen
}}

This works great and does exactly what its suppose to do and inputs the button press in the serial monitor, but my problem is getting it to work for the application i want. I want to have the button press get stored in a array and be compared to another array like a password. and if the array's match it will run a function. I had this working when i hooked up the 3x4 matrix keypad pin by pin to my arduino and used the Keypad library, and i used the strcmp to see if the strings matched up, but I am absolutly lost on how to do it with the serial keypad. Everything i have tried isn't working and any help is appreciated. Thank You

Everything i have tried isn’t working and any help is appreciated.

Since we have no idea what you tried, we can’t really help you, can we?

If that code works, I’d really be surprised. You appear to have two things (the keyboard and the PC application) connected to the same serial port. Normally, that is a recipe for disaster.

If it works, then the character that was pressed on the keyboard is in num, which, of course, is a lousy name. You can store that value anywhere else, including in an array. But, you have to write code to do that, including keeping track of where in the array to store the next character.

Here is a video of the code working and exactly what it does. http://www.youtube.com/watch?feature=player_embedded&v=X_oZyMVdtmw
I have made a second char array to compare against the num array and used the strcmp and that did not work. I tried changing the code so i could compare the first part for example

if(num[0]==password[0]){
digitalWrite(ledRed, HIGH);
delay(2000);
digitalWrite(ledRed, LOW);
}

But that did not work either. Basically I’m trying to get this code to run different functions if you enter in different keystrokes.

I have made a second char array to compare against the num array and used the strcmp and that did not work.

http://snippets-r-us.com might be able to help you. Our psychic isn't due to start until the 12th of never. If you can't wait that long, you'll have to post all of your code.

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

but for some reason i can't figure out how to compare the strings.

So, you decided to post some completely unrelated code, instead. How useful.

if(num[0]==password[0]){
digitalWrite(ledRed, HIGH);
delay(2000);
digitalWrite(ledRed, LOW);
}

was clearly related to your attempt to collect data in an array. Whether that was right or wrong is not possible to determine from the snippet you posted. You need to post ALL of THAT code. Not some other code for some other hardware.

The code I posted is not unrelated, I want to use the same basis of that code with the serial encoder. Like I said in my first post

I am absolutly lost on how to do it with the serial keypad.

What I did didn't work and I deleted the code since it did not work I am asking for help on how other people would think it would work or how to do what the other code did with a Serial Keypad Encoder?