int x;voidsetup(){// put your setup code here, to run once:pinMode(4, INPUT);pinMode(5, OUTPUT);pinMode(7, OUTPUT);pinMode(6, OUTPUT);}voidloop(){// put your main code here, to run repeatedly:if(digitalRead(4)== HIGH){
x =random(5,8);digitalWrite(x, HIGH);delay(500);digitalWrite(x, LOW);delay(500);}else{
Serial.println("开关未按下!!!");}}
voidsetup(){// put your setup code here, to run once:
Serial.begin(9600);pinMode(7, INPUT_PULLUP);pinMode(8, OUTPUT);}voidloop(){// put your main code here, to run repeatedly:int a =digitalRead(7);
Serial.println(a);if(a == LOW){digitalWrite(8, HIGH);delay(100);digitalWrite(8, LOW);delay(100);}}
int x =0;voidsetup(){// put your setup code here, to run once:pinMode(7, INPUT_PULLUP);pinMode(9, OUTPUT);}voidloop(){// put your main code here, to run repeatedly:if(!digitalRead(7)){while(!digitalRead(7)){delay(10);}
x++;if(x %2==0){digitalWrite(9, HIGH);}else{digitalWrite(9, LOW);}}}