int led = 3;
int button = 2;
int value = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(button,INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
//三挡灯光切换
while(1){
if(digitalRead(button) == LOW){
delay(80);
if(digitalRead(button) == LOW){
delay(80);
Serial.println("按下并写入");
Serial.println(value);
analogWrite(led,value);
value = value + 80;
Serial.println("现在a的值:");
Serial.println(value);
};
if(value > 255){
value = 0;
Serial.println("a清零");
}
}
}
}