Go Down

Topic: Matlab While loop to blink led (Read 112 times) previous topic - next topic

keshara2032

hey everyone, im sorry for asking this question but i made a tic tac toe project for college with arduino and i assigned X to light a led continuously and O to blink the led. but i dont know how to make it blink until we win the game or its drawn. i dont know how to use the while loop or for loop for this.
I have attached the code too.

UKHeliBob

Quote
i dont know how to use the while loop or for loop for this.
Don't use either.  Let the loop() function do what its name implies and loop

Each time through loop() check whether it is time to change the state of the LEDs by comparing millis() and the value from millis() saved when the current state was entered.  If it is time then change the state and save the millis() value.  If no then carry on round loop() again doing what you need to such as reading inputs.

This is known as the BlinkWithoutDelay principle and there is an example in the IDE with that name.  For an extended version look at Several things at the same time
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

UKHeliBob

Is this a Matlab or an Arduino question ?
The code that you posted certainly will not compile on an Arduino.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up