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);
}