I would like to blink leds in many patterns. I wanna ask if my code is a "programmer solution". I create an incrementing variable named "counter" and switch LED state if counter reach some value. I am not sure about using equal operator in if condition like if(counter == 20). How to avoid jumping into LED switching part every counter increment another way?
Can someone rewrite this program into "shape"?
Another solution is to change a timer value to next overflow, is it better?
if(timer_10ms_flag == 1) {
timer_10ms_flag == 0;
if((counter > 100) || (reset_counter == 1)) {
counter = 0;
reset_counter = 0;
}
if(mode == 0) {
if(counter == 0) {
LED_ON;
}
if(counter == 20) {
LED_OFF;
}
}
if(mode == 1) {
if(counter == 0) {
LED_ON;
}
if(counter == 10) {
LED_OFF;
}
if(counter == 20) {
LED_ON;
}
if(counter == 40) {
LED_OFF;
}
}
counter++;
}
Aucun commentaire:
Enregistrer un commentaire