这是这两个loop程序,我把他们复制到一起,就只能运行前面那部分,寻迹这部分就执行不了。
两个不同的功能合并在一个系统里,直接把代码放在一起,哪有那么简单,必须分析代码之间是否可能产生互相影响的问题。
创建setup()时,该函数设置初始值等一些初始化操作。该函数是Arduino运行控制的函数,所有的实时控制逻辑都在该方法内执行。
const int buttonPin = 3;
// setup initializes serial and the button pin
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
// loop checks the button pin each time,
// and will send serial if it is pressed
void loop()
{
if (digitalRead(buttonPin) == HIGH)
Serial.write('H');
else
Serial.write('L');
delay(1000);
}