// Pins
const int freqPot = A0;      // Pot to control frequency (10 to 30Hz)
const int pulsePot = A1;     // Pot to control pulse width (1ms to 10ms)
const int out1 = 8;
const int out2 = 9;

void setup() {
  pinMode(out1, OUTPUT);
  pinMode(out2, OUTPUT);
  digitalWrite(out1, LOW);
  digitalWrite(out2, LOW);
}

void loop() {
  // Read potentiometers
  int freqVal = analogRead(freqPot);    // 0–1023
  int pulseVal = analogRead(pulsePot);  // 0–1023

  // Map frequency pot: 10 to 30 Hz
  float frequency = map(freqVal, 0, 1023, 10, 30);
  float period = 1000.0 / frequency; // in milliseconds

  // Map pulse width: 1ms to 10ms
  float pulseWidth = map(pulseVal, 0, 1023, 1, 10);

  // Ensure pulse width doesn't exceed half of the period
  if (pulseWidth > period / 2) {
    pulseWidth = period / 2;
  }

  // Alternate outputs
  digitalWrite(out1, HIGH);
  digitalWrite(out2, LOW);
  delay(pulseWidth);
  delay(period / 2 - pulseWidth);

  digitalWrite(out1, LOW);
  digitalWrite(out2, HIGH);
  delay(pulseWidth);
  delay(period / 2 - pulseWidth);
}