2

I've been working on project for children showing the codes used by atc transponder. I've used a keypad and a ×ばつ2 display , where user types a 4 digit code and display shows condition related to the code E.g. typing 7500 on keypad will show hijack on display

What has went wrong??

My code is ------
 #include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);//RS,EN,D4,D5,D6,D7
#include <Keypad.h>//header for keypad commands enabling
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
 {'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'#','0','*','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 0, 1, 2, 3 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 4, 5, 6, 7 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char inputArray[4]; //array to gather user keypad presses
char Vfr[4] = {'1','2','0','0'}; //array to hold keypad password
char Gliders[4] = {'1','2','0','2'};
char Hijack[4] = {'7','5','0','0'};
char Comfail[4] = {'7','6','0','0'};
char Emerg[4] = {'7','7','0','0'};
char Mic[4] = {'7','7','7','7'};
int i = 0;
int state = 1;
void setup()
{
 for(int k=8;k<14;k++)
 {
 pinMode(k,OUTPUT);//pins 8-14 are enabled as output
 }
 lcd.begin(16, 2);//initializing LCD
}
void loop()
{
while (state = 1);
{
 lcd.setCursor(0, 0);
 char key = kpd.getKey();
 //if a key is presseds
 if(key)
 {
 inputArray[i] = key; //store entry into array
 i++;
 lcd.clear(); //print keypad character entry to serial port
 if (key=='C');
 {
 lcd.setCursor(0, 1);
 lcd.print("Reset");
 i=0; //reset i
 }
 if (i == 4) //if 4 presses have been made
 {
 {
 //match input array to password array
 if (inputArray[0] == Vfr[0] &&
 inputArray[1] == Vfr[1] &&
 inputArray[2] == Vfr[2] &&
 inputArray[3] == Vfr[3])
 {
 lcd.setCursor(0, 1);
 lcd.print("VFR");
 }
 }
 {
 //match input array to password array
 if (inputArray[0] == Gliders[0] &&
 inputArray[1] == Gliders[1] &&
 inputArray[2] == Gliders[2] &&
 inputArray[3] == Gliders[3])
 {
 lcd.setCursor(0, 1);
 lcd.print("GLIDERS");
 }
 }
 {
 //match input array to password array
 if (inputArray[0] == Hijack[0] &&
 inputArray[1] == Hijack[1] &&
 inputArray[2] == Hijack[2] &&
 inputArray[3] == Hijack[3])
 {
 lcd.setCursor(0, 1);
 lcd.print("HIJACK");
 }
 }
 {
 //match input array to password array
 if (inputArray[0] == Comfail[0] &&
 inputArray[1] == Comfail[1] &&
 inputArray[2] == Comfail[2] &&
 inputArray[3] == Comfail[3])
 {
 lcd.setCursor(0, 1);
 lcd.print("COMMFAIL");
 }
 }
 {
 //match input array to password array
 if (inputArray[0] == Emerg[0] &&
 inputArray[1] == Emerg[1] &&
 inputArray[2] == Emerg[2] &&
 inputArray[3] == Emerg[3])
 {
 lcd.setCursor(0, 1);
 lcd.print("EMERGENCY!");
 }
 }
 {
 //match input array to password array
 if (inputArray[0] == Emerg[0] &&
 inputArray[1] == Emerg[1] &&
 inputArray[2] == Emerg[2] &&
 inputArray[3] == Emerg[3])
 {
 lcd.setCursor(0, 1);
 lcd.print("EMERGENCY!");
 }
 }
 {
 //match input array to password array
 if (inputArray[0] == Mic[0] &&
 inputArray[1] == Mic[1] &&
 inputArray[2] == Mic[2] &&
 inputArray[3] == Mic[3])
 {
 lcd.setCursor(0, 1);
 lcd.print("MILITARY IC");
 }
 }
 } 
}
lcd.print(key); 
}
}
asked Apr 27, 2017 at 8:10

1 Answer 1

1
while (state = 1);

This line is a loop that will go around forever so long as you can set the variable state to 1. What you mean is:

while (state == 1)

You don't need semicolons at the end of conditionals, here is another:

 if (key=='C');

If you fix those two bugs, you'll get a lot further.

answered Apr 27, 2017 at 8:23
8
  • Thank you I tried and now display seems to give some output but it's some weird character Commented Apr 27, 2017 at 8:31
  • The keys I'm typing on keypad are appearing on same cursor position ????? Commented Apr 27, 2017 at 10:17
  • You aren't incrementing the cursor position manually so have you initialised the LCD so it increments the cursor position? Commented Apr 27, 2017 at 10:21
  • How can I do it? Commented Apr 27, 2017 at 10:21
  • 1
    should I define x as int? From 0 to 16 right?? Commented Apr 27, 2017 at 10:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.