// Constants
const int pulsePin = 8; // Arduino pin 9 for the pulse output
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(pulsePin, OUTPUT); // Set pulsePin as output
Serial.println("pls enter numbers");
}
void loop() {
while (Serial.available() == 0) {
delay(10);
}
float highTime = Serial.parseFloat(); // Read float value from serial input
// Check if the value is within the valid range (1 to 2 ms)
// Calculate low time
float lowTime = 20.0 - highTime;
// Generate the pulse
for (int i = 0; i <= 30; i++)
{
digitalWrite(pulsePin, HIGH); // Set pulsePin high
delayMicroseconds(highTime * 1000); // Delay for the high time
digitalWrite(pulsePin, LOW); // Set pulsePin low
delayMicroseconds(lowTime * 1000); // Delay for the remaining cycle time
}
}