/********* 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: "Bluetooth Servo Control"
	- Source Code compiled for: Arduino Uno
	- Source Code created on: 2024-04-14 23:07:35

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* The mobile app shall communicate with the HC05 */
	/* module to control the robotic arm. The code shall */
	/* define the arm's initial position. When the button */
	/* is pressed, the arm shall move towards the */
	/* specified item, perform pick and place operation. */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include <SoftwareSerial.h>
#include <Servo.h>

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void moveArm(int position);

/***** DEFINITION OF PWM OUTPUT PINS *****/
const uint8_t servo1_Servomotor_PWMSignal_PIN_D3 = 3;
const uint8_t servo2_Servomotor_PWMSignal_PIN_D5 = 5;
const uint8_t servo3_Servomotor_PWMSignal_PIN_D6 = 6;
const uint8_t servo6_Servomotor_PWMSignal_PIN_D9 = 9;

/***** DEFINITION OF Software Serial *****/
const uint8_t serial_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
const uint8_t serial_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
SoftwareSerial serial_HC05_mySerial(serial_HC05_mySerial_PIN_SERIAL_RX_A1, serial_HC05_mySerial_PIN_SERIAL_TX_A0);

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
uint8_t servo1_Servomotor_PWMSignal_PIN_D3_rawData = 0;
uint8_t servo2_Servomotor_PWMSignal_PIN_D5_rawData = 0;
uint8_t servo3_Servomotor_PWMSignal_PIN_D6_rawData = 0;
uint8_t servo6_Servomotor_PWMSignal_PIN_D9_rawData = 0;

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float servo1_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
float servo2_Servomotor_PWMSignal_PIN_D5_phyData = 0.0;
float servo3_Servomotor_PWMSignal_PIN_D6_phyData = 0.0;
float servo6_Servomotor_PWMSignal_PIN_D9_phyData = 0.0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo6;

void setup(void)
{
	// Attach the servo motors to their respective pins
	servo1.attach(servo1_Servomotor_PWMSignal_PIN_D3);
	servo2.attach(servo2_Servomotor_PWMSignal_PIN_D5);
	servo3.attach(servo3_Servomotor_PWMSignal_PIN_D6);
	servo6.attach(servo6_Servomotor_PWMSignal_PIN_D9);

	// Initialize the serial communication
	serial_HC05_mySerial.begin(9600);
}

void loop(void)
{
	// Check if there is data available from the HC05 module
	if (serial_HC05_mySerial.available())
	{
		// Read the position value from the serial communication
		int position = serial_HC05_mySerial.read();
		moveArm(position);
	}
}

void moveArm(int position)
{
	// Set the position for all the servo motors
	servo1.write(position);
	servo2.write(position);
	servo3.write(position);
	servo6.write(position);
}