cancel
Showing results for 
Search instead for 
Did you mean: 

i am facing issue while whenever key pressed whole column is high(turned on led)

Girish1
Associate III

KeyInputMemory[column_count] = (uint16_t) HAL_GPIO_ReadPin(rowport, GPIO_PIN_All);

 

/* If the key at the current column is pressed (considering an active low setup),

store the LED state in the LEDOutputMemory. */

if (KeyInputMemory[column_count] == 0)

{

LedOutputMemory[column_count] = GPIO_PIN_RESET; // Store the LED ON state for the respective column

}

else

{

LedOutputMemory[column_count] = GPIO_PIN_SET; // Store the LED OFF state for the respective column

}

 

// Now actually write to GPIOA based on LEDOutputMemory

HAL_GPIO_WritePin(GPIOA, (1 << column_count), LedOutputMemory[column_count]);

 

/* Compare with stored key input */

if (KeyInputMemory[column_count] == StoredKeyInput[column_count])

{

KeyInputCounter[column_count]++;

if (KeyInputCounter[column_count] > 5)

{

StoredKeyInput[column_count] = KeyInputMemory[column_count];

}

 

}

else

{

StoredKeyInput[column_count] = KeyInputMemory[column_count];

KeyInputCounter[column_count] = 0;

 

}

Hi in above code, i am reading the key inputs from the port b and stored and compared. i have a physical keyboard each key is soldered correspondind led, whenever the key is pressed particular led should glow, but in my scenario whenever the key is pressed whole column is high means whole column led's turning on.....

1 REPLY 1
Peter BENSCH
ST Employee

As already mentioned in your previous thread, it would be useful to mention your hardware connections, i.e. the circuitry of the keyboard you are using, and the IOC file so that one can understand what you actually want to do and how.

BTW: you can also make it easier for other community members by inserting code with the function Insert/Edit code sample:

  • ... = Expand toolbar (you will find the three dots on the top far right of the editor window)
  • </> = Insert/Edit code sample

The inserted code will then be inserted in a much more readable format, e.g. like that (please note that the code did not become more functional, but only prettier):

KeyInputMemory[column_count] = (uint16_t) HAL_GPIO_ReadPin(rowport, GPIO_PIN_All);

/*If the key at the current column is pressed (considering an active low setup),
store the LED state in the LEDOutputMemory. */
if (KeyInputMemory[column_count] == 0)
{
	LedOutputMemory[column_count] = GPIO_PIN_RESET;	// Store the LED ON state for the respective column
}
else
{
	LedOutputMemory[column_count] = GPIO_PIN_SET;	// Store the LED OFF state for the respective column
}

// Now actually write to GPIOA based on LEDOutputMemory
HAL_GPIO_WritePin(GPIOA, (1 << column_count), LedOutputMemory[column_count]);

/*Compare with stored key input */
if (KeyInputMemory[column_count] == StoredKeyInput[column_count])
{
	KeyInputCounter[column_count]++;
	if (KeyInputCounter[column_count] > 5)
	{
		StoredKeyInput[column_count] = KeyInputMemory[column_count];
	}
}
else
{
	StoredKeyInput[column_count] = KeyInputMemory[column_count];
	KeyInputCounter[column_count] = 0;
}

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.