-
Notifications
You must be signed in to change notification settings - Fork 1
[개인 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
base: main
Are you sure you want to change the base?
Conversation
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; | ||
} |
There was a problem hiding this comment.
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한다.
/* 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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메인 루프에서는 딜레이 없는 Polling 방식으로 진동 센서로 부터 진동이 감지되었는지를 검사한다.
진동이 감지되면 didVibrate
를 1로 set한다.
No description provided.