// Define analog input pins for sine, triangle, and square wave inputs
#define sineInput A0       // Analog input pin for sine wave input
#define triangleInput A1   // Analog input pin for triangle wave input
#define squareInput A2     // Analog input pin for square wave input
 
// Initialize serial communication at a baud rate of 152000
void setup() {
  Serial.begin(152000); // Set the baud rate for serial communication
}
 
// Main execution loop
void loop() {
  // Read analog input values and convert to engineering units
  float sine = R2E(sineInput, 0, 5);          // Convert raw analog value to engineering unit for sine input (range: 0-5V)
  float triangle = R2E(triangleInput, 0, 5);  // Convert raw analog value to engineering unit for triangle input (range: 0-5V)
  float square = R2E(squareInput, 0, 5);      // Convert raw analog value to engineering unit for square input (range: 0-5V)
 
  // Print the converted values to the serial monitor
  Serial.println(
    "Sine:" + String(sine, 2) +
    ", Triangle:" + String(triangle, 2) +
    ", Square:" + String(square, 2)
  );
}
 
// Function to convert raw analog input value to engineering unit using linear scaling
float R2E(uint8_t pin, float min, float max) {
  int value = analogRead(pin);      // Read the raw analog input value
  return value * max / 1023 + min; // Convert the raw value to engineering unit using linear scaling
}
WaveBreakout