根据参数循环调用的函数 [英] Called function that loops depending on the argument
问题描述
我有一个函数 LED_MAIN()
,它的工作是通过调用另一个私有的函数 LED_MAIN_LINE()
来点亮LED,这意味着我正在测试该代码我只会调用 LED_MAIN()
.
I have a function LED_MAIN()
whose work is to light up LEDs by calling upon another function LED_MAIN_LINE()
which is private to it, meaning when I am testing the code I will only call LED_MAIN()
.
void LED_MAIN (void) //main function (public) to light all LEDs
{
int i;
int LED_NO_UP = 10 ; //number of LEDs on line going up
int LED_NO_DOWN = 10; //number of LEDs on line coming down
void LED_MAIN_LINE ( int no ); //private function to light LEDs on either side i.e on line going up and on line coming down
for (i=0 ; 1<20 ; i++) //first eliminate any errors in all 20 LEDs
{
LED_ERROR [i] = 0;
}
for ( i=0 ; i<LED_NO_UP ; i++ ) //light LEDs on one side. MAX 10 LEDs. LEDs #1-10
{
LED_MAIN_LINE (i);
}
for ( i=0 ; i<LED_NO_DOWN ; i++ ) //light LEDs on the other side. LEDs #11-20
{
LED_MAIN_LINE (i+10);
}
}
void LED_MAIN_LINE ( int no ) //definition of the actual LED lighting function (private to void LED_MAIN (void))
{
//currently no reference to argument int no in this function
for (i = 10 ; i > 0 ; i++)
{
led_status [no][i] = led_status [no] [i-1]
}
// continued......
}
应该为每个存在的LED执行
LED_MAIN_LINE()
.如果每条线上有10个LED,它将循环20次(10x2).如果有5个LED,它将仅执行5次&.很快.参数是LED的数量.但是,它是由void LED_MAIN()
调用的,这就是发生循环的地方.
LED_MAIN_LINE()
is supposed to be executed for every LED that there is. If there are 10 LEDs on either line, it will loop 20 times (10x2). If there are 5 LEDs it will only be executed 5 times & so on. The argument is the number of LEDs. However, it is being called by void LED_MAIN()
and this is where the looping will happen.
看看我对void LED_MAIN_LINE()
的定义,我没有传递有关LED数量的参数.我已经在 LED_MAIN()
中完成了此操作.我想知道,这个定义正确吗?我应该在哪里传递期望使 LED_MAIN_LINE()
循环的LED数量?使用当前代码,我的测试结果与预期不符.
Looking at my definition of void LED_MAIN_LINE()
however, I have not passed an argument for the number of LEDs. I have done this in LED_MAIN()
. I wonder, is this definition correct? Where should I pass the number of LEDs expected to make LED_MAIN_LINE()
loop? With the current code my test results are not as expected.
推荐答案
LED_NO_UP和LED_NO_DOWN为0.因此,由于 i<当
. i = 0
时,不可能使用0
LED_NO_UP and LED_NO_DOWN are 0. So the for loops in your code are never executed because i < 0
is not possible when i = 0
.
在第一个for循环中还有 1< 20
.
Also you have 1<20
in the first for loop.
这篇关于根据参数循环调用的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!