arduino pwm按键控制灯的明暗

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);
}

arduino pwm按键控制灯的明暗

上一篇:超声波+红外线避障小车(Arduino + L298P电机驱动扩展板)


下一篇:Wemos D1 RGB 全彩灯