#include <Servo.h>
Servo myservo; // Create servo object to control a servo
int buttonPin = 4; // Push button pin
int pos = 0; // Variable to store the servo position
void setup() {
myservo.attach(3); // Attach the servo on pin 3 to the servo object
pinMode(buttonPin, INPUT_PULLUP); // Initialize the push button pin as an input with internal pull-up resistor
}
void loop() {
int buttonState = digitalRead(buttonPin); // Read the state of the push button
if (buttonState == LOW) { // Button is pressed
if (pos < 90) {
pos++; // Increment the servo position
myservo.write(pos); // Move the servo to the new position
delay(15); // Delay to allow the servo to move
}
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
rgb1:R
rgb1:COM
rgb1:G
rgb1:B
ultrasonic1:VCC
ultrasonic1:TRIG
ultrasonic1:ECHO
ultrasonic1:GND
ultrasonic2:VCC
ultrasonic2:TRIG
ultrasonic2:ECHO
ultrasonic2:GND
servo1:GND
servo1:V+
servo1:PWM
r2:1
r2:2
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
r1:1
r1:2
r3:1
r3:2
r4:1
r4:2
r5:1
r5:2
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL