Skip to content

[개인 Homework] Tx에서 진동을 감지하여 Rx로 송신하기 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

hepheir
Copy link
Member

@hepheir hepheir commented Oct 29, 2024

No description provided.

@hepheir hepheir self-assigned this Oct 29, 2024
Comment on lines +49 to +69
int didVibrate = 0;

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART2_UART_Init(void);
static void MX_TIM2_Init(void);
/* USER CODE BEGIN PFP */
int __io_putchar(int ch)
{
HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, HAL_MAX_DELAY);
return ch;
}

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
printf("Vib : %d \n\r", didVibrate);
didVibrate = 0;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

타이머 인터럽트(1초 주기)에서 didVibrate값을 읽어와 출력한다.

didVibrate는 마지막 출력 이후로 부터 1번이라도 진동이 감지되었으면 1로 set되어있다.

출력을 마친 후에는 didVibrate의 값을 clear한다.

Comment on lines +115 to +125
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
didVibrate |= HAL_GPIO_ReadPin(vibrtion_transducer_GPIO_Port, vibrtion_transducer_Pin);

/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메인 루프에서는 딜레이 없는 Polling 방식으로 진동 센서로 부터 진동이 감지되었는지를 검사한다.

진동이 감지되면 didVibrate를 1로 set한다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant