/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
unsigned long time_ms=0;
short count=250;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_NVIC_Init(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
*
* @retval None
*/
int main(void)
{
/* USER CODE BEGIN 1 */
unsigned long time_prems=0;
unsigned char flag_s1=0;
/* USER CODE END 1 */
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_TIM2_Init();
MX_TIM3_Init();
/* Initialize interrupts */
MX_NVIC_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim2);
HAL_TIM_PWM_Start(&htim3,TIM_CHANNEL_1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
if((HAL_GPIO_ReadPin(S1_GPIO_Port,S1_Pin)==0)&&(flag_s1==0))
{
HAL_Delay(5);
if((HAL_GPIO_ReadPin(S1_GPIO_Port,S1_Pin)==0)&&(flag_s1==0))
{
flag_s1=1;
count+=50;
if(count>=1000)
count=1000;
__HAL_TIM_SET_COMPARE(&htim3,TIM_CHANNEL_1,count);
}
}
if((HAL_GPIO_ReadPin(S1_GPIO_Port,S1_Pin)==1)&&(flag_s1==1))
{
HAL_Delay(5);
if((HAL_GPIO_ReadPin(S1_GPIO_Port,S1_Pin)==1)&&(flag_s1==1))
{
flag_s1=0;
}
}
__HAL_TIM_SET_COMPARE(&htim3,TIM_CHANNEL_1,count);
if(time_ms-time_prems>=500)
{
time_ms=time_prems;
//HAL_GPIO_TogglePin(LED2_GPIO_Port,LED2_Pin);
}
}
/* USER CODE END 3 */
/**
* @brief This function is executed in case of error occurrence.
* @param file: The file name as string.
* @param line: The line in file as a number.
* @retval None
*/
void _Error_Handler(char *file, int line)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
while(1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */