A small production, children will like it very much. Material list: 1 Arduino UNO R3 1 SG90 2 LEDs 1 button Please implement it with reference to the following code.
一个小制作,小朋友会很喜欢
物料清单:
Arduino UNO R3 1个
SG90 1个
LED 2个
按钮 1个
请把参考以下代码实现
#include
Servo myservo;
int led1Pin=8;
int led2Pin=11;
int buttonPin=13;
int i;
int val=0;
int val1=0;
void setup() {
Serial.println("Run control");
myservo.attach(2);
Serial.begin(9600);
pinMode(led1Pin,OUTPUT);
pinMode(buttonPin,INPUT);
}
void loop() {
val=digitalRead(buttonPin);
if(val==1){
digitalWrite(led1Pin,HIGH );
digitalWrite( led2Pin,HIGH );
myservo.write(155);
delay(500);
myservo.write(60);
delay(200);
myservo.write(25);
delay(400);
myservo.write(155);
delay(200);
digitalWrite(led1Pin,LOW);
digitalWrite( led2Pin,LOW );
}
}