/********* 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: Distance Measurement
	- Source Code NOT compiled for: Arduino Uno
	- Source Code created on: 2024-09-04 07:14:55

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

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* void setup() {    // put your setup code her */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include <Ultrasonic.h>	// https://github.com/ErickSimoes/Ultrasonic

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

/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t Sensor_HC_SR04_Echo_PIN_D6 = 6;

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t Red_LEDRGB_Red_PIN_D2 = 2;
const uint8_t Red_LEDRGB_Green_PIN_D3 = 3;
const uint8_t Buzzer_ActiveBuzzer_output_PIN_D4 = 4;
const uint8_t Sensor_HC_SR04_Trigger_PIN_D5 = 5;

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool Red_LEDRGB_Red_PIN_D2_rawData = 0;
bool Red_LEDRGB_Green_PIN_D3_rawData = 0;
bool Buzzer_ActiveBuzzer_output_PIN_D4_rawData = 0;
bool Sensor_HC_SR04_Trigger_PIN_D5_rawData = 0;

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float Red_LEDRGB_Red_PIN_D2_phyData = 0.0;
float Red_LEDRGB_Green_PIN_D3_phyData = 0.0;
float Buzzer_ActiveBuzzer_output_PIN_D4_phyData = 0.0;
float Sensor_HC_SR04_Trigger_PIN_D5_phyData = 0.0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create an Ultrasonic object
Ultrasonic ultrasonic(Sensor_HC_SR04_Trigger_PIN_D5, Sensor_HC_SR04_Echo_PIN_D6); // Initialize the ultrasonic object

void setup(void) 
{    
	// Initialize serial communication
	Serial.begin(9600); // Start serial communication at 9600 baud rate

	// Set pin modes for input and output
	pinMode(Sensor_HC_SR04_Echo_PIN_D6, INPUT);
	pinMode(Red_LEDRGB_Red_PIN_D2, OUTPUT);
	pinMode(Red_LEDRGB_Green_PIN_D3, OUTPUT);
	pinMode(Buzzer_ActiveBuzzer_output_PIN_D4, OUTPUT);
	pinMode(Sensor_HC_SR04_Trigger_PIN_D5, OUTPUT);

	// Attach the ultrasonic sensor to the specified pins
	// This is done through the constructor of the Ultrasonic object
}

void loop(void) 
{
	// Main code to run repeatedly
	updateOutputs(); // Refresh output data

	// Read the distance from the ultrasonic sensor
	int distance = ultrasonic.read(); // Get distance in centimeters

	// Print the distance to the Serial Monitor
	Serial.print("Distance in CM: ");
	Serial.println(distance);

	delay(1000); // Wait for 1 second before the next reading
}

void updateOutputs() 
{
	// Update the output pins based on the raw data
	digitalWrite(Red_LEDRGB_Red_PIN_D2, Red_LEDRGB_Red_PIN_D2_rawData);
	digitalWrite(Red_LEDRGB_Green_PIN_D3, Red_LEDRGB_Green_PIN_D3_rawData);
	digitalWrite(Buzzer_ActiveBuzzer_output_PIN_D4, Buzzer_ActiveBuzzer_output_PIN_D4_rawData);
	digitalWrite(Sensor_HC_SR04_Trigger_PIN_D5, Sensor_HC_SR04_Trigger_PIN_D5_rawData);
}

/* END CODE */