Hi All,
I am working on a project for my embedded systems class and have been stuck at this section. We are building a 5 floor elevator controlled by the SamD20 (Arm). A 4x4 keypad gives us our inputs, and sends PWM according to the state of the elevator (up or down).
The elevator moves okay but I cannot figure out how to get the board to check for a new input while the elevator is moving. Part of the assignment is to store new inputs and move the elevator to that state after the desired next state has been reached. For example if I am on floor 1, I press floor 3, the elevator starts moving, and I suddenly press 5 while it is moving; I need it to stop at floor 3, and then continue to floor 5. Currently, I can only take a new keypad press AFTER the elevator has stopped moving. Please help!
Here is the condensed read keypad function:
unsigned char read_keypad (void)
{
//establish variables used in the read_keypad function
unsigned char key = 'n';
int row;
//established array used to read keypad
unsigned int keypad_row_bit[4]={PORT_PA22,PORT_PA23,PORT_PA08,PORT_PA09};
//setting a character matrix for the outputs read from keypad
unsigned char keypad_key[4][4]={{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
...
...
//Checking to see that a button in first row is pressed
PORTA->OUTTGL.reg= PORT_PA10;
for (row=1;row<=4;row++)
{
if (!(PORTA->IN.reg & keypad_row_bit[row-1]))
{
key = keypad_key[0][row-1];
}
}
//Checking to see that a button in second row is pressed
PORTA->OUTTGL.reg=~(PORT_PA10);
PORTA->OUTSET.reg=~(PORT_PA11);
for (row=1;row<=4;row++)
{
if (!(PORTA->IN.reg & keypad_row_bit[row-1]))
{
key = keypad_key[1][row-1];
}
}
//Checking to see that a button in third row is pressed
PORTA->OUTTGL.reg=~(PORT_PA11);
PORTA->OUTSET.reg=~(PORT_PA20);
for (row=1;row<=4;row++)
{
if (!(PORTA->IN.reg & keypad_row_bit[row-1]))
{
key = keypad_key[2][row-1];
}
}
I am working on a project for my embedded systems class and have been stuck at this section. We are building a 5 floor elevator controlled by the SamD20 (Arm). A 4x4 keypad gives us our inputs, and sends PWM according to the state of the elevator (up or down).
The elevator moves okay but I cannot figure out how to get the board to check for a new input while the elevator is moving. Part of the assignment is to store new inputs and move the elevator to that state after the desired next state has been reached. For example if I am on floor 1, I press floor 3, the elevator starts moving, and I suddenly press 5 while it is moving; I need it to stop at floor 3, and then continue to floor 5. Currently, I can only take a new keypad press AFTER the elevator has stopped moving. Please help!
Here is the condensed read keypad function:
unsigned char read_keypad (void)
{
//establish variables used in the read_keypad function
unsigned char key = 'n';
int row;
//established array used to read keypad
unsigned int keypad_row_bit[4]={PORT_PA22,PORT_PA23,PORT_PA08,PORT_PA09};
//setting a character matrix for the outputs read from keypad
unsigned char keypad_key[4][4]={{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
...
...
//Checking to see that a button in first row is pressed
PORTA->OUTTGL.reg= PORT_PA10;
for (row=1;row<=4;row++)
{
if (!(PORTA->IN.reg & keypad_row_bit[row-1]))
{
key = keypad_key[0][row-1];
}
}
//Checking to see that a button in second row is pressed
PORTA->OUTTGL.reg=~(PORT_PA10);
PORTA->OUTSET.reg=~(PORT_PA11);
for (row=1;row<=4;row++)
{
if (!(PORTA->IN.reg & keypad_row_bit[row-1]))
{
key = keypad_key[1][row-1];
}
}
//Checking to see that a button in third row is pressed
PORTA->OUTTGL.reg=~(PORT_PA11);
PORTA->OUTSET.reg=~(PORT_PA20);
for (row=1;row<=4;row++)
{
if (!(PORTA->IN.reg & keypad_row_bit[row-1]))
{
key = keypad_key[2][row-1];
}
}