2022-10-09 07:03 AM
I'm trying to blink variation of morze code with specific string on yellow led, but the led just turns on and stays on for a little bit and then turns off.
When I try to debug it step by step it works as it should, but the moment I press run, it does the same think. If anyone can shed some light on this, I would really appreciate it!
Thank you!
char* name= "text";
char *string;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
for(;*name!= '\0';name++) {
string = morze(*name);
for(int i = 0;string[i] != '\0';i++) {
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1);
if(string[i] == '.'){
HAL_Delay(500);
}else if(string[i] == '-') {
HAL_Delay(1000);
}else {
int a = 0;
}
HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_1);
}
}
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
char* morze(char a)
{
switch (a) {
case 'x':
return "-..-";
case 'e':
return ".";
case 't':
return "-";
default:
break;
}
return NULL;
}
Solved! Go to Solution.
2022-10-09 07:59 AM
Then it's the wrong place. You have to wait for a pause in a code position, where the LED is off!
2022-10-09 07:16 AM
You have forgot the delay between the dots and dashes.
2022-10-09 07:37 AM
if I add delay there it does the same think just for longer
2022-10-09 07:59 AM
Then it's the wrong place. You have to wait for a pause in a code position, where the LED is off!
2022-10-09 09:09 AM
Yea, I'm dumb, I was putting it in wrong place.