i found the problem I dont know how to explain that
this problem maybe related with IDE complier?
this is my TEST code
#define SubFunction1 0
#define SubFunction2 1
#define DirectForMode1 2 //Didnt work
#define DirectForMode2 3
#define testMode DirectForMode2 // SubFunction1 SubFunction2 DirectForMode DirectForMode2
#define BaudRate 115200
void setup()
{
Serial.begin(BaudRate);
}
void loop()
{
while(1)
{
#if testMode == SubFunction1
test();
#elif testMode == SubFunction2
test2();
#elif testMode == DirectForMode1
for(int i,j = 0; i < 20; i++)
{
Serial.println("Test while+for for(int i,j = 0; i < 20; i++)");
}
#else //DirectForMode2
for(int i = 0,j = 0; i < 20; i++)
{
Serial.println("Test while+for for(int i = 0,j = 0; i < 20; i++)");
}
#endif
}
}
void test(void)
{
for(int i,j = 0; i < 20; i++)
{
Serial.println("Test while+for with SubFunction for(int i,j = 0; i < 20; i++)");
}
}
void test2(void)
{
for(int i = 0,j = 0; i < 20; i++)
{
Serial.println("Test while+for with SubFunction for(int i = 0,j = 0; i < 20; i++)");
}
}
this code have 4 situation(situation 3 is Fail)
1.SubFunction1(with Subroutine in while(1) and for(int i,j = 0; i < 20; i++))
2.SubFunction2(with Subroutine in while(1) and for(int i = 0,j = 0; i < 20; i++))
3.DirectForMode1(without Subroutine in while(1) and for(int i,j = 0; i < 20; i++))
4.DirectForMode2(without Subroutine in while(1) and for(int i = 0,j = 0; i < 20; i++))
in situation 1 and 3
i use (for(int i,j = 0; i < 20; i++)) ,only different part situation1 is use Subroutine ,situation3 not use Subroutine
in situation 4 and 3
i write code in while(1) directly,only different part situation4 is use for(int i = 0,j = 0; i < 20; i++),situation3 use for(int i,j = 0; i < 20; i++)
i cant explain code doesnt work in situation3 ,i am just curiously
sketch_apr15c.ino (1.12 KB)