/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: 2_servo_wireless
- Source Code compiled for: Arduino Uno
- Source Code created on: 2023-10-20 07:54:39
- Source Code generated by: Lohith bala
********* Pleasedontcode.com **********/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
#include
/****** SYSTEM REQUIREMENT 1 *****/
/* Should be able to manually control the servo using */
/* potentiometer */
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Lava_PushButton_PIN_D2 = 2; // Define the pin number for the push button
/***** DEFINITION OF ANALOG INPUT PINS *****/
const uint8_t Potentiometer_PIN_A0 = A0; // Define the pin number for the potentiometer
/***** DEFINITION OF SERVO OUTPUT PINS *****/
const uint8_t Servo_PIN_D9 = 9; // Define the pin number for the servo
/***** GLOBAL VARIABLES *****/
Servo servo; // Create a servo object
void setup(void)
{
// put your setup code here, to run once:
pinMode(Lava_PushButton_PIN_D2, INPUT_PULLUP); // Set the push button pin as input with internal pull-up resistor
servo.attach(Servo_PIN_D9); // Attach the servo to the servo pin
}
void loop(void)
{
// put your main code here, to run repeatedly:
int potValue = analogRead(Potentiometer_PIN_A0); // Read the analog value from the potentiometer
int servoPos = map(potValue, 0, 1023, 0, 180); // Map the potentiometer value to servo position (0-180 degrees)
servo.write(servoPos); // Set the servo position based on the potentiometer value
delay(10); // Delay for stability
}