I am working on a lab for one of my classes and the lab required the use of a 4x4 keypad.
There is much more to the lab but this specific section says that when "C" is pressed the user can input a number, after inputting the number (up to three digits) the user then presses the "#" character and the value inputted gets sent to the servo motor along with being displayed on an LCD screen.
here is the code I have for the servo and it seems like it should work when I read it but then nothing happens when it runs:
//================================================================
void Servoscreen(void)
{
ServoScreenSetup();
static int pressedKeyCount = 0;
char firstchar, secondchar, thirdchar;
int thisscreen = 1;
static int finishinput = 1;
char key;
int finConversion = 0;
int ThreeDigNum, TwoDigNum, OneDigNum;
//----------------------------------------------------------------
do
{
key = myKeypad.getKey();
if(key == 'C')
{
finishinput = 0;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Input Servo Val");
lcd.setCursor(0,1);
lcd.print("Then press #");
}
//----------------------------------------------------------------
while(finishinput = 0)
{
pressedKeyCount = 0;
key = myKeypad.getKey();
if(key && pressedKeyCount == 0);
{
firstchar = key;
pressedKeyCount = pressedKeyCount + 1;
}
key = myKeypad.getKey();
if(key && pressedKeyCount == 1);
{
secondchar = key;
pressedKeyCount = pressedKeyCount + 1;
}
key = myKeypad.getKey();
if(key && pressedKeyCount == 2);
{
thirdchar = key;
pressedKeyCount = pressedKeyCount + 1;
}
if(key == '#')
{
finishinput = 1;
}
}
//----------------------------------------------------------------
if(pressedKeyCount == 1)
{
int Firstdecimal = CharToInt(firstchar);
finConversion = 1;
OneDigNum = Firstdecimal;
}
if(pressedKeyCount == 2)
{
int Firstdecimal = CharToInt(firstchar);
int Seconddecimal = CharToInt(secondchar);
Firstdecimal = Firstdecimal * 10;
finConversion = 1;
TwoDigNum = Firstdecimal + Seconddecimal;
}
if(pressedKeyCount == 3)
{
int Firstdecimal = CharToInt(firstchar);
int Seconddecimal = CharToInt(secondchar);
int Thirddecimal = CharToInt(thirdchar);
Firstdecimal = Firstdecimal * 100;
Seconddecimal = Seconddecimal * 10;
finConversion = 1;
ThreeDigNum = Firstdecimal + Seconddecimal + Thirddecimal;
}
//----------------------------------------------------------------
if(finConversion == 1)
{
lcd.clear();
ServoScreenSetup();
switch(pressedKeyCount)
{
case 1:
lcd.setCursor(7,1);
lcd.print(OneDigNum);
case 2:
lcd.setCursor(7,1);
lcd.print(TwoDigNum);
case 3:
lcd.setCursor(7,1);
lcd.print(ThreeDigNum);
}
}
//----------------------------------------------------------------
key = myKeypad.getKey();
if(key == 'B')
{
choice = '2';
thisscreen = 0;
}
if(key == 'D')
{
choice = '_';
thisscreen = 0;
}
//----------------------------------------------------------------
}while(thisscreen == 1);
lcd.clear();
}
//=================================================================
void BDtext (void)
{
lcd.setCursor(11,0);
lcd.print("prv-B");
lcd.setCursor(11,1);
lcd.print("nxt-D");
}
//=================================================================
void ServoScreenSetup(void)
{
lcd.clear();
BDtext();
lcd.setCursor(1,0);
lcd.print("Servo deg");
//----------------------------------------------------------------
lcd.setCursor(1,1);
lcd.print("A");
lcd.setCursor(6,1);
lcd.print("C");
}
//==================================================================
int CharToInt(char character)
{
int decimal;
switch(character)
{
case '0':
decimal = 0;
break;
case '1':
decimal = 1;
break;
case '2':
decimal = 2;
break;
case '3':
decimal = 3;
break;
case '4':
decimal = 4;
break;
case '5':
decimal = 5;
break;
case '6':
decimal = 6;
break;
case '7':
decimal = 7;
break;
case '8':
decimal = 8;
break;
case '9':
decimal = 9;
break;
}
return decimal;
}
//==================================================================
This is no way completed code (i have been working on this all day and can getting tired) like how there are no comments which I will add later (not there because with the amount of time I had to change the code retyping the comments became tiresome)
When I run the code I can get to the screen on the LCD where is says "Servo deg" and has "A" and "C" on the next line. When I press C I get the next screen saying to input the Servo Val and Pressing # but after that nothing happens
Also, and I do not know if this is the reason why it will not work, due to COVID-19 my classes are all online and the professor had us use a simulator instead of purchasing an Arduino because of the components we use are in the classroom which is currently inaccessible, the simulator does give components we can use. The simulator we are using is TinkerCad and my total program is currently more than 400 lines (but I believe this should not matter because the Servo Motor is a function that the Arduino runs and ignore the rest of the code)
if needed I can post the entire code and send a picture of my circuit
also sorry for the formatting if this i have never used this forum before