Question
*STM32F030F4p6 Problem with GPIO_EXTI1 Pin*
Hello everyone,
So I am trying to take Input from the sensor and then turn on the LED_1/Sound on and another senarove is that whne I prace the GPIO_EXTI1 turn on the another LED_2. but what is hapning is when senser is not givin Input even then LED_1/Sound is on.
Bun whin i use the TWO code sepratly THe code work with no problem
1. while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if (!button_pressed) {
handle_sensor_input();
}
}
// Handle sensor input
2. void handle_sensor_input(void) {
GPIO_PinState a = HAL_GPIO_ReadPin(SENSOR1_PORT, SENSOR1_PIN);
GPIO_PinState b = HAL_GPIO_ReadPin(SENSOR2_PORT, SENSOR2_PIN);
// Process the sensor state
if (a == GPIO_PIN_RESET || b == GPIO_PIN_RESET) {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_SET);
HAL_Delay(100);
int randomIndex = rand() % size;
int randomNumber = numbers[randomIndex];
printf("Randomly selected number: %d\n", randomNumber);
selectRandomLED(randomNumber);
// }
} else {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_3, GPIO_PIN_RESET);
}
}
3. // EXTI Line1 External Interrupt ISR Handler CallBackFun
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == GPIO_PIN_1) { // If The INT Source Is EXTI Line1 (PB1 Pin)
button_pressed = !button_pressed; // Toggle the button press state
if (button_pressed) {
HAL_GPIO_WritePin(GPIOA, LED_1_Pin | LED_2_Pin | LED_3_Pin | BUZZER_PIN, GPIO_PIN_RESET); // Toggle The Output (LED) Pin
}
}
}