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);
}
}
1 Answer 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.
-
Thank you I tried and now display seems to give some output but it's some weird characterMcGucket– McGucket2017年04月27日 08:31:03 +00:00Commented Apr 27, 2017 at 8:31
-
The keys I'm typing on keypad are appearing on same cursor position ?????McGucket– McGucket2017年04月27日 10:17:28 +00:00Commented 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?Code Gorilla– Code Gorilla2017年04月27日 10:21:03 +00:00Commented Apr 27, 2017 at 10:21
-
-
1should I define x as int? From 0 to 16 right??McGucket– McGucket2017年04月27日 10:31:33 +00:00Commented Apr 27, 2017 at 10:31