我创建了一个Arduino草图,用于打开或关闭两组LED。该程序的想法是在每个循环中以一定数量的步骤循环运行。到目前为止,我已经编写了草图,我可以定义多达12个不同的步骤(参见下面的代码),但是添加更多步骤非常复杂,需要多行代码。我想知道,如果你们中的任何人都可以帮助想出一种方法来替换我的开关案例,循环遍历各个步骤。由于我的编程技巧非常基础,我感谢任何改进我的代码的建议。
每个步骤的参数定义:
unsigned long cycles = 1000; // number of cycles
byte steps = 4; // number of steps to repeat in cycles
unsigned long timebasis = 1000; // factor to multiply with ms to set time basis -> 1 results in 1 ms time basis, 1000 results in 1 s etc
//Step 1
#define s1_intensity_LEDcolor1 1000 // intensity 660 nm at step 1
#define s1_intensity_LEDcolor2 0 // intensity 740 nm at step 1
#define s1_duration 5 //length of step 1
//Step 2
#define s2_intensity_LEDcolor1 0 // intensity 660 nm at step 2
#define s2_intensity_LEDcolor2 0 // intensity 740 nm at step 2
#define s2_duration 2 // length of step 2
//Step 3
#define s3_intensity_LEDcolor1 0 // intensity 660 nm at step 3
#define s3_intensity_LEDcolor2 1000 // intensity 740 nm at step 3
#define s3_duration 1 // length of step 3
//Step 4
#define s4_intensity_LEDcolor1 0 // intensity 660 nm at step 4
#define s4_intensity_LEDcolor2 0 // intensity 740 nm at step 4
#define s4_duration 4 // length of step 4
//Step 5
#define s5_intensity_LEDcolor1 100 // intensity 660 nm at step 5
#define s5_intensity_LEDcolor2 1000 // intensity 740 nm at step 5
#define s5_duration 50 // length of step 5
//Step 6
#define s6_intensity_LEDcolor1 0 // intensity 660 nm at step 6
#define s6_intensity_LEDcolor2 1000 // intensity 740 nm at step 6
#define s6_duration 80 // length of step 6
//Step 7
#define s7_intensity_LEDcolor1 300 // intensity 660 nm at step 7
#define s7_intensity_LEDcolor2 0 // intensity 740 nm at step 7
#define s7_duration 50 // length of step 7
//Step 8
#define s8_intensity_LEDcolor1 0 // intensity 660 nm at step 8
#define s8_intensity_LEDcolor2 0 // intensity 740 nm at step 8
#define s8_duration 60 // length of step 8
//Step 9
#define s9_intensity_LEDcolor1 0 // intensity 660 nm at step 9
#define s9_intensity_LEDcolor2 1000 // intensity 740 nm at step 9
#define s9_duration 70 // length of step 9
//Step 10
#define s10_intensity_LEDcolor1 700 // intensity 660 nm at step 10
#define s10_intensity_LEDcolor2 0 // intensity 740 nm at step 10
#define s10_duration 30 // length of step 10
//Step 11
#define s11_intensity_LEDcolor1 0 // intensity 660 nm at step 11
#define s11_intensity_LEDcolor2 0 // intensity 740 nm at step 11
#define s11_duration 80 // length of step 11
//Step 12
#define s12_intensity_LEDcolor1 1000 // intensity 660 nm at step 12
#define s12_intensity_LEDcolor2 1000 // intensity 740 nm at step 12
#define s12_duration 90 // length of step 12
Timer1.initialize(timebasis*1000); // setting the time base
Timer1.attachInterrupt(doSomething); // execute function "doSomething" every X µs based on time base
void doSomething()
{
counter++;
}
总结各个步长:
#define s1_dur s1_duration
#define s2_dur (s1_duration + s2_duration)
#define s3_dur (s1_duration + s2_duration + s3_duration)
#define s4_dur (s1_duration + s2_duration + s3_duration + s4_duration)
#define s5_dur (s1_duration + s2_duration + s3_duration + s4_duration + s5_duration)
#define s6_dur (s1_duration + s2_duration + s3_duration + s4_duration + s5_duration + s6_duration)
#define s7_dur (s1_duration + s2_duration + s3_duration + s4_duration + s5_duration + s6_duration + s7_duration)
#define s8_dur (s1_duration + s2_duration + s3_duration + s4_duration + s5_duration + s6_duration + s7_duration + s8_duration)
#define s9_dur (s1_duration + s2_duration + s3_duration + s4_duration + s5_duration + s6_duration + s7_duration + s8_duration + s9_duration)
#define s10_dur (s1_duration + s2_duration + s3_duration + s4_duration + s5_duration + s6_duration + s7_duration + s8_duration + s9_duration + s10_duration)
#define s11_dur (s1_duration + s2_duration + s3_duration + s4_duration + s5_duration + s6_duration + s7_duration + s8_duration + s9_duration + s10_duration + s11_duration)
#define s12_dur (s1_duration + s2_duration + s3_duration + s4_duration + s5_duration + s6_duration + s7_duration + s8_duration + s9_duration + s10_duration + s11_duration + s12_duration)
步骤功能:
void step1()
{
if(debug == 1)
{
time_unit(s1_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s1_intensity_LEDcolor1);
lcd.print(s1_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s1_intensity_LEDcolor2);
lcd.print(s1_intensity_LEDcolor2);
}
setColor(color1, s1_intensity_LEDcolor1);
setColor(color2, s1_intensity_LEDcolor2);
}
void step2()
{
if(debug == 1)
{
time_unit(s2_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s2_intensity_LEDcolor1);
lcd.print(s2_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s2_intensity_LEDcolor2);
lcd.print(s2_intensity_LEDcolor2);
}
setColor(color1, s2_intensity_LEDcolor1);
setColor(color2, s2_intensity_LEDcolor2);
}
void step3()
{
if(debug == 1)
{
time_unit(s3_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s3_intensity_LEDcolor1);
lcd.print(s3_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s3_intensity_LEDcolor2);
lcd.print(s3_intensity_LEDcolor2);
}
setColor(color1, s3_intensity_LEDcolor1);
setColor(color2, s3_intensity_LEDcolor2);
}
void step4()
{
if(debug == 1)
{
time_unit(s4_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s4_intensity_LEDcolor1);
lcd.print(s4_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s4_intensity_LEDcolor2);
lcd.print(s4_intensity_LEDcolor2);
}
setColor(color1, s4_intensity_LEDcolor1);
setColor(color2, s4_intensity_LEDcolor2);
}
void step5()
{
if(debug == 1)
{
time_unit(s5_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s5_intensity_LEDcolor1);
lcd.print(s5_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s5_intensity_LEDcolor2);
lcd.print(s5_intensity_LEDcolor2);
}
setColor(color1, s5_intensity_LEDcolor1);
setColor(color2, s5_intensity_LEDcolor2);
}
void step6()
{
if(debug == 1)
{
time_unit(s6_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s6_intensity_LEDcolor1);
lcd.print(s6_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s6_intensity_LEDcolor2);
lcd.print(s6_intensity_LEDcolor2);
}
setColor(color1, s6_intensity_LEDcolor1);
setColor(color2, s6_intensity_LEDcolor2);
}
void step7()
{
if(debug == 1)
{
time_unit(s7_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s7_intensity_LEDcolor1);
lcd.print(s7_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s7_intensity_LEDcolor2);
lcd.print(s7_intensity_LEDcolor2);
}
setColor(color1, s7_intensity_LEDcolor1);
setColor(color2, s7_intensity_LEDcolor2);
}
void step8()
{
if(debug == 1)
{
time_unit(s8_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s8_intensity_LEDcolor1);
lcd.print(s8_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s8_intensity_LEDcolor2);
lcd.print(s8_intensity_LEDcolor2);
}
setColor(color1, s8_intensity_LEDcolor1);
setColor(color2, s8_intensity_LEDcolor2);
}
void step9()
{
if(debug == 1)
{
time_unit(s9_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s9_intensity_LEDcolor1);
lcd.print(s9_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s9_intensity_LEDcolor2);
lcd.print(s9_intensity_LEDcolor2);
}
setColor(color1, s9_intensity_LEDcolor1);
setColor(color2, s9_intensity_LEDcolor2);
}
void step10()
{
if(debug == 1)
{
time_unit(s10_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s10_intensity_LEDcolor1);
lcd.print(s10_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s10_intensity_LEDcolor2);
lcd.print(s10_intensity_LEDcolor2);
}
setColor(color1, s10_intensity_LEDcolor1);
setColor(color2, s10_intensity_LEDcolor2);
}
void step11()
{
if(debug == 1)
{
time_unit(s11_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s11_intensity_LEDcolor1);
lcd.print(s11_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s11_intensity_LEDcolor2);
lcd.print(s11_intensity_LEDcolor2);
}
setColor(color1, s11_intensity_LEDcolor1);
setColor(color2, s11_intensity_LEDcolor2);
}
void step12()
{
if(debug == 1)
{
time_unit(s12_duration);
lcd.setCursor(0,1);
lcd.print("C1:");
fill_up_4(s12_intensity_LEDcolor1);
lcd.print(s12_intensity_LEDcolor1);
lcd.print("|C2:");
fill_up_4(s12_intensity_LEDcolor2);
lcd.print(s12_intensity_LEDcolor2);
}
setColor(color1, s12_intensity_LEDcolor1);
setColor(color2, s12_intensity_LEDcolor2);
}
void laststep()
{
setColor(color1, 0);
setColor(color2, 0);
counter = 0;
cycle_counter++;
}
附件功能:
//----------------------- Checks digits of value and fills up to a total of 4 digits with spaces ------
void fill_up_4(int value_length)
{
if(value_length < 10) // value smaller 10, write 3 spaces to LCD
{
lcd.print(" ");
}
else if(value_length < 100) // value smaller 100, write 2 spaces to LCD
{
lcd.print(" ");
}
else if(value_length < 1000) // value smaller 1000, write 1 spaces to LCD
{
lcd.print(" ");
}
}
//----------------------- Checks time value and sets time unit accordingly ------------------------
void time_unit(unsigned long time_value)
{
unsigned long basecorrectedtime = time_value * timebasis;
if(basecorrectedtime < 1000) // value smaller 1 sec -> display in ms
{
lcd.print(basecorrectedtime/1000);
lcd.print("ms");
}
else if(basecorrectedtime < 60000) // value smaller 1 min -> display in sec
{
lcd.print(basecorrectedtime/(float)1000); // (float) results in decimal numbers
lcd.print(" s");
}
else if(basecorrectedtime < 3600000) // value smaller 1 hour -> display in min
{
lcd.print(basecorrectedtime/(float)60000);
lcd.print(" m");
}
else // value bigger than 1 hour, display in hours
{
lcd.print(basecorrectedtime/(float)3600000);
lcd.print(" h");
}
}
主开关案例
switch(steps)
{
case 1: switch(counter) // 1 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/1| ");
}
step1();
break;
case s1_dur:
laststep();
break;
}
case 2: switch(counter) // 2 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/2| ");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/2| ");
}
step2();
break;
case s2_dur:
laststep();
break;
}
break;
case 3: switch(counter) // 3 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/3| ");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/3| ");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/3| ");
}
step3();
break;
case s3_dur:
laststep();
break;
}
break;
case 4: switch(counter) // 4 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/4| ");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/4| ");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/4| ");
}
step3();
break;
case s3_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 4/4| ");
}
step4();
break;
case s4_dur:
laststep();
break;
}
break;
case 5: switch(counter) // 5 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/5| ");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/5| ");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/5| ");
}
step3();
break;
case s3_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 4/5| ");
}
step4();
break;
case s4_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 5/5| ");
}
step5();
break;
case s5_dur:
laststep();
break;
}
break;
case 6: switch(counter) // 6 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/6| ");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/6| ");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/6| ");
}
step3();
break;
case s3_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 4/6| ");
}
step4();
break;
case s4_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 5/6| ");
}
step5();
break;
case s5_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 6/6| ");
}
step6();
break;
case s6_dur:
laststep();
break;
}
break;
case 7: switch(counter) // 7 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/7| ");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/7| ");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/7| ");
}
step3();
break;
case s3_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 4/7| ");
}
step4();
break;
case s4_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 5/7| ");
}
step5();
break;
case s5_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 6/7| ");
}
step6();
break;
case s6_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 7/7| ");
}
step7();
break;
case s7_dur:
laststep();
break;
}
break;
case 8: switch(counter) // 8 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/8| ");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/8| ");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/8| ");
}
step3();
break;
case s3_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 4/8| ");
}
step4();
break;
case s4_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 5/8| ");
}
step5();
break;
case s5_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 6/8| ");
}
step6();
break;
case s6_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 7/8| ");
}
step7();
break;
case s7_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 8/8| ");
}
step8();
break;
case s8_dur:
laststep();
break;
}
break;
case 9: switch(counter) // 9 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/9| ");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/9| ");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/9| ");
}
step3();
break;
case s3_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 4/9| ");
}
step4();
break;
case s4_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 5/9| ");
}
step5();
break;
case s5_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 6/9| ");
}
step6();
break;
case s6_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 7/9| ");
}
step7();
break;
case s7_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 8/9| ");
}
step8();
break;
case s8_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 9/9| ");
}
step9();
break;
case s9_dur:
laststep();
break;
}
break;
case 10: switch(counter) // 10 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/10|");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/10|");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/10|");
}
step3();
break;
case s3_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 4/10|");
}
step4();
break;
case s4_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 5/10|");
}
step5();
break;
case s5_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 6/10|");
}
step6();
break;
case s6_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 7/10|");
}
step7();
break;
case s7_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 8/10|");
}
step8();
break;
case s8_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 9/10|");
}
step9();
break;
case s9_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St.10/10|");
}
step10();
break;
case s10_dur:
laststep();
break;
}
break;
case 11: switch(counter) // 11 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/11|");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/11|");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/11|");
}
step3();
break;
case s3_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 4/11|");
}
step4();
break;
case s4_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 5/11|");
}
step5();
break;
case s5_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 6/11|");
}
step6();
break;
case s6_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 7/11|");
}
step7();
break;
case s7_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 8/11|");
}
step8();
break;
case s8_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 9/11|");
}
step9();
break;
case s9_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St.10/11|");
}
step10();
break;
case s10_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St.11/11|");
}
step11();
break;
case s11_dur:
laststep();
break;
}
break;
case 12: switch(counter) // 12 step program
{
case 0:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 1/12|");
}
step1();
break;
case s1_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 2/12|");
}
step2();
break;
case s2_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 3/12|");
}
step3();
break;
case s3_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 4/12|");
}
step4();
break;
case s4_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 5/12|");
}
step5();
break;
case s5_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 6/12|");
}
step6();
break;
case s6_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 7/12|");
}
step7();
break;
case s7_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 8/12|");
}
step8();
break;
case s8_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St. 9/12|");
}
step9();
break;
case s9_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St.10/12|");
}
step10();
break;
case s10_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St.11/12|");
}
step11();
break;
case s11_dur:
if(debug == 1)
{
lcd.setCursor(0,0);
lcd.print("St.12/12|");
}
step12();
break;
case s12_dur:
laststep();
break;
}
break;
}
提前多多谢谢!
ozy
答案 0 :(得分:0)
好的,我不会查看您的所有代码,但我会尝试给您一些想法。
如果要使用for循环,则应使用arrays而不是定义。类似的东西:
#define NUMBER_OF_STEPS 12;
const int DURATION[NUMBER_OF_STEPS] = { 5, 2, 1, … };
const int COLOR1[NUMBER_OF_STEPS] = {1000, 0, 0, … };
const int COLOR2[NUMBER_OF_STEPS] = { 0, 0, 1000, … };
循环执行所有步骤的示例如下所示:
for(int i=0; i<NUMBER_OF_STEPS; i++){
//do whatever…
//set colors using the array
setColor(color1, COLOR1[i] );
setColor(color2, COLOR2[i] );
}
请参阅Arduino Reference上的for statements。 for循环还有一个例子。
现在去缩小代码:)