CCCPaste

"Switch Servo" rev_01

/********* 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: "Switch Servo"
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2024-01-22 07:39:19

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* when turn on switch rotate and lock and when off */
	/* the switch rotate and unlock */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);

/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t servo_Servomotor_PWMSignal_PIN_D3 = 3;
const uint8_t servo_Servomotor_PWMSignal_PIN_D5 = 5;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
Servo servo_Servomotor_D3;
Servo servo_Servomotor_D5;

const uint8_t switch_PIN = 2; // Define the switch input pin here

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(switch_PIN, INPUT_PULLUP); // Set the switch pin as input with internal pull-up resistor
  servo_Servomotor_D3.attach(servo_Servomotor_PWMSignal_PIN_D3);
  servo_Servomotor_D5.attach(servo_Servomotor_PWMSignal_PIN_D5);

  // Set initial positions
  servo_Servomotor_D3.write(0);
  servo_Servomotor_D5.write(0);
}

void loop(void)
{
  // put your main code here, to run repeatedly:

  // Check the switch state
  bool switchState = digitalRead(switch_PIN);

  if (switchState == HIGH)
  {
    // Switch is turned on, rotate and lock servos
    servo_Servomotor_D3.write(90);
    servo_Servomotor_D5.write(90);
  }
  else
  {
    // Switch is turned off, rotate and unlock servos
    servo_Servomotor_D3.write(0);
    servo_Servomotor_D5.write(0);
  }

  delay(100); // Adjust the delay time as needed
}