#include <Servo.h>
const int servoPin = 9; // PWM pin for servo control
const int motorSpeedPin = 3; // Pin for motor speed control
const int ledPin = 13; // Pin for LED
const int buttonPin = 2; // Pin for pushbutton
const int potPin = A0; // Analog pin for potentiometer
Servo servo;
int motorSpeed = 0;
void setup() {
pinMode(motorSpeedPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
servo.attach(servoPin);
}
void loop() {
// Read potentiometer value
int potValue = analogRead(potPin);
// Map potentiometer value to servo angle (0 to 180)
int servoAngle = map(potValue, 0, 1023, 0, 180);
servo.write(servoAngle);
// Map potentiometer value to motor speed (0 to 255)
motorSpeed = map(potValue, 0, 1023, 0, 255);
analogWrite(motorSpeedPin, motorSpeed);
// Check if pushbutton is pressed
if (digitalRead(buttonPin) == HIGH) {
// Turn on LED
digitalWrite(ledPin, HIGH);
} else {
// Turn off LED
digitalWrite(ledPin, LOW);
}
delay(100); // Adjust delay as needed for responsiveness
}