how to cancel (stop) a piece of code?

HyperUniverse
Posts: 33
Joined: Fri Oct 29, 2021 11:20 pm

how to cancel (stop) a piece of code?

Postby HyperUniverse » Sun Nov 07, 2021 7:27 pm

Hi,

I've got this piece of code that is changing the colour of 10 LEDs:

Code: Select all

void Circle_Rainbow() {
	sendData(Turn_LED3_Red, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED4_Amber, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED5_Blue, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED6_White, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED7_Green, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED8_Red, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED9_Amber, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED0_Blue, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED1_White, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED2_Green, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED3_Red, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED4_Amber, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED5_Blue, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED6_White, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED7_Green, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED8_Red, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED9_Amber, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED0_Blue, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED1_White, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
	sendData(Turn_LED2_Green, 8);
	vTaskDelay(75 / portTICK_PERIOD_MS);
}	
how can I cancel it at any point, after I've started it, if I wish to?
I'll use a button to cancel it, but I can't figure out how.
Right now, if I start it, I need to wait until is finished.

Maybe I need to modify the code so I won't change the LED's colour from inside a void?

Anybody can give me a hint?

Thanks,
Regards.

Victoria Nope
Posts: 75
Joined: Fri Dec 04, 2020 9:56 pm

Re: how to cancel (stop) a piece of code?

Postby Victoria Nope » Sun Nov 07, 2021 11:12 pm

You can use a timer from which you would send the data in turn for each LED with every tick. And such timer you'd then control from button interrupt routine.

HyperUniverse
Posts: 33
Joined: Fri Oct 29, 2021 11:20 pm

Re: how to cancel (stop) a piece of code?

Postby HyperUniverse » Mon Nov 08, 2021 3:38 pm

Thanks Victoria Nope, I'll need a couple of days to do that.

Regards.

Who is online

Users browsing this forum: atx823, MicroController and 181 guests