int pwm = 128;
void setup() {
Serial.begin(9600);
Serial.println("串口打开!!");
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(6, OUTPUT);
}
void loop() {
boolean a;
boolean b;
a = digitalRead(2);
b = digitalRead(3);
Serial.println(pwm);
if (a == 0 && pwm > 0 ){
analogWrite(6, pwm);
pwm--;
}else if(b == 0 && pwm < 255){
analogWrite(6, pwm);
pwm++;
}
delay(20);
}