Question about my derivative of PA3HCM's keyer code

The note at the top of the code explains a lot. My question is why is the delay(1) necessary for the subroutine at the end to run? Thanks.

/*  KJ4FX Cootie Keyer
 *  This code is based on the work of PA3HCM. Thanks Ernest.
 *  I (KJ4FX) have made significant changes: adapted it to run
 *  on Digispark clones, changed most of the names of things,
 *  incorporated internal pullups on the paddle inputs, used a
 *  formula to convert the potentiometer input to dit length,
 *  and done away with the audio out function.
 *  This is my version 01, dated 25 July 2022.
 */

#define ditIn 3
#define dahIn 2
#define toXmtr 1
#define fromPot 2

int ditLength;

void setup()
{
  pinMode(ditIn, INPUT_PULLUP);
  pinMode(dahIn, INPUT_PULLUP);
  pinMode(toXmtr, OUTPUT);
  digitalWrite(toXmtr, LOW);
}

void loop()
{
  ditLength = 60000 / (map(analogRead(fromPot), 0, 1023, 25, 5) * 44);
  if(!digitalRead(ditIn)) 
  {
    transmit(ditLength);
    delay(ditLength);
  }
  if(!digitalRead(dahIn))
  {
    transmit(ditLength*3);
    delay(ditLength);
  }
}

void transmit(int ditLength)
{
  digitalWrite(toXmtr, HIGH);
  for (int j=0; j < (ditLength); j++)
  delay(1);
  digitalWrite(toXmtr, LOW);
}

Could be replaced with:
delay(ditLength);

johnwasser, that works like a champ. Thanks a bunch. (It's a little embarrassing that I couldn't figure it out.)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.