我正在编写一段代码,以使两个LED灯按特定的顺序闪烁。
我的代码
int main()
{
int blue = 3;
int green = 4;
int time = 1;
int i = 1;
int j = 1;
greenLED = 1;
blueLED = 1;
wait(1);
for(time; time<green*blue; time++)
{
if (time == green*i)
{
blueLED = 1;
i=i+1;
}
if(time == blue*j)
{
greenLED = 1;
j=j+1;
}
wait(1);
}
}
我的问题是它说我的for循环无效。我假设这意味着我的for循环未运行,因为我的for循环的表达式没有意义或者没有拾取我拥有的任何变量?有人可以帮我一下,告诉我为什么吗?
欢呼
答案 0 :(得分:0)
我认为这就是你想要的
int main()
{
int blue = 3;
int green = 4;
int time = 1;
int i = 1;
int j = 1;
int greenLED = 1;
int blueLED = 1;
for(time; time<green*blue; time++)
{
blueLED=0;
greenLED=0;
printf("for loop start\n");
if (time == green*i)
{
printf("if1\n");
blueLED = 1;
i=i+1;
}
if(time == blue*j)
{
printf("if2\n");
greenLED = 1;
j=j+1;
}
printf("endforloop\n");
printf("%d\n",greenLED);
printf("%d\n",blueLED);
}
}
您看到for循环正在运行