So I am creating a custom library for a school project with my group and we hit a snag when implementing it. We are using a custom library for an LCD display and for a PS/2 keyboard. We are wanting to condense the amount of code needed to get user input from the keyboard display it on the LCD and check if it is a valid input. This means the custom library named Functions.h needs to use those libraries to do the functions it needs to. I have them both included in the .cpp and .h file for our custom library but that doesn't solve it. Any suggestions to try would be very helpful! I can also attach my cpp and h code if that is need to clarify anything about my code.
#include <Functions.h>
#include <PS2Keyboard.h>
#include <LiquidCrystal_I2C.h>
const int KeyData = 8; //data pin of keyboard
const int KeyClock = 3; //clock pin of keyboard
char welcome[]="RISC-V Demo"; //welcome message
char input; //var to handle keystrokes
String command=""; //var to store the completed command that will be checked to see if valid
int commandIndex=0; //var to know where at in command to take a char away when backspace is pressed
String numConvert=""; //var that will be need to be converted to int
String listOfCommands="1. ADD 2. SUB 3. AND";
int commandNum; //var for switch statement linked to the command entered by the user
int numConvertIndex=0; //var to know where at in numConvert to take a char away when backspace is pressed
int bitStream[32]; //var to store the bits to be sent to the FPGA
PS2Keyboard keyboard; //declare instance of keyboard
LiquidCrystal_I2C lcd(0x27,20,4); //delcare instance of lcd
functions fpga;
void setup() {
lcd.init(); //start lcd
lcd.backlight(); //turns lcd backlight on
delay(1000);
keyboard.begin(KeyData, KeyClock); //starts keyboard
for(int j=0; j<2; j++){ //loops to display the welcome message
for(int i=0; i<4; i++){
lcd.setCursor(5,i);
lcd.print(welcome);
delay(500);
lcd.clear();
}
}
}
void loop() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter your command:");
lcd.setCursor(0,1);
lcd.print(command);
delay(50);
if(keyboard.available()){
input=keyboard.read();
if(input == PS2_DELETE){ //if the keystroke is the backspace, remove the last keystroke from the command string and change commandIndex accordingly
if(commandIndex!=0){
command.remove(commandIndex-1);
commandIndex-=1;}
}
else if(input == PS2_ENTER){ //if enter is pressed check to see a vaild command then run the command
//code needs to be inserted to change the command into a respecting int value to be used in the switch statement below
commandNum = fpga.which_command(command);
switch (commandNum){
case 1://if the add command is entered ask for numbers
fpga.ADD(bitStream);
fpga.transmit(bitStream);
command="";
break;
case 2:
fpga.SUB(bitStream);
fpga.transmit(bitStream);
command="";
break;
case 3:
fpga.AND(bitStream);
fpga.transmit(bitStream);
command="";
break;
default:
lcd.setCursor(2,0);
lcd.print("Invalid command");
command="";
delay(50);
}
}
else if (isAlphaNumeric(input)){
command.concat(input);
command.toUpperCase();
commandIndex++;
}
else{
lcd.setCursor(0,2);
lcd.print("That's not a vaild input");
}
delay(100);
}
}
Error Message
Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
C:\Users\Kyle\Documents\Arduino\libraries\Custom_lib\Functions.cpp: In member function 'void functions::user_input()':
C:\Users\Kyle\Documents\Arduino\libraries\Custom_lib\Functions.cpp:234:4: error: 'lcd' was not declared in this scope
lcd.clear();
^
C:\Users\Kyle\Documents\Arduino\libraries\Custom_lib\Functions.cpp:240:4: error: 'input' was not declared in this scope
input = keyboard.read();
^
C:\Users\Kyle\Documents\Arduino\libraries\Custom_lib\Functions.cpp:240:12: error: 'keyboard' was not declared in this scope
input = keyboard.read();
^
C:\Users\Kyle\Documents\Arduino\libraries\Custom_lib\Functions.cpp:295:3: error: 'lcd' was not declared in this scope
lcd.clear();
^
C:\Users\Kyle\Documents\Arduino\libraries\Custom_lib\Functions.cpp:300:3: error: 'input' was not declared in this scope
input = keyboard.read();
^
C:\Users\Kyle\Documents\Arduino\libraries\Custom_lib\Functions.cpp:300:11: error: 'keyboard' was not declared in this scope
input = keyboard.read();
^
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.