串口用到了管脚1,
不知道你是如果观察变量的a的。
[mw_shl_code=cpp,true]// two_button.ino
#define buttonPin_inc 4
#define buttonPin_dec 5
long a = 0;
void setup()
{
pinMode(buttonPin_inc, INPUT_PULLUP);
pinMode(buttonPin_dec, INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
if(digitalRead(buttonPin_inc)==LOW)
{
delay(40);
if(digitalRead(buttonPin_inc)==HIGH)
{a++; Serial.println(a,DEC);}
}
if(digitalRead(buttonPin_dec)==LOW)
{
delay(40);
if(digitalRead(buttonPin_dec)==HIGH)
{a--; Serial.println(a,DEC);}
}
}
[/mw_shl_code]
|