<commit_before>// One Arduino controls transmitters on pins 3 and 11, alternately
// sending out pings from the two of them, simulating two synchronized
// transmitter stations sending out pings in turn.

enum {
  TX_PIN_1 = 3,
  TX_PIN_2 = 11,
  FREQ = 25000u,  // Hz
  DURATION = 5u,  // ms
};

void setup() {
  pinMode(TX_PIN_1, OUTPUT);
  pinMode(TX_PIN_2, OUTPUT);
}

void loop() {
  tone(TX_PIN_1, FREQ, DURATION);
  delay(100u);
  tone(TX_PIN_2, FREQ, DURATION);
  delay(1000u);
}
<commit_msg>Make each transmitter controlled by two pins.<commit_after>// One Arduino controls two transmitters, alternately sending
// out pings from the two of them, simulating two synchronized
// transmitter stations sending out pings in turn.

#define TX_1_PORT PORTD
#define TX_2_PORT PORTB

enum {
  TX_1_PIN_1 = 2,
  TX_1_PIN_2 = 3,
  TX_2_PIN_1 = 10,
  TX_2_PIN_2 = 11,
  FREQ = 25000u,  // Hz
  PERIOD = 1000000u / FREQ,  // μs
  HALF_PERIOD = PERIOD / 2u,  // μs
  DURATION = 5000u,  // μs
  SPACING = 100000u,  // μs
  CYCLE = 1000000u,  // μs
};

void setup() {
  pinMode(TX_1_PIN_1, OUTPUT);
  pinMode(TX_1_PIN_2, OUTPUT);
  pinMode(TX_2_PIN_1, OUTPUT);
  pinMode(TX_2_PIN_2, OUTPUT);
}

void loop() {
  unsigned long beginning = micros();

  // Send out ping from transmitter 1
  unsigned long time = micros() - beginning;
  unsigned long next = time;
  while (time < DURATION) {
    TX_1_PORT = TX_1_PORT & (~(1 << (TX_1_PIN_2 % 8))) | (1 << (TX_1_PIN_1 % 8));
    next += HALF_PERIOD;
    while (micros() - beginning < next)
      ;
    TX_1_PORT = TX_1_PORT & (~(1 << (TX_1_PIN_1 % 8))) | (1 << (TX_1_PIN_2 % 8));
    next += HALF_PERIOD;
    while ((time = micros() - beginning) < next)
      ;
  }

  // Send out a ping from transmitter 2
  while ((time = micros() - beginning) < SPACING)
    ;
  next = time;
  while (time < SPACING + DURATION) {
    TX_2_PORT = TX_2_PORT & (~(1 << (TX_2_PIN_2 % 8))) | (1 << (TX_2_PIN_1 % 8));
    next += HALF_PERIOD;
    while (micros() - beginning < next)
      ;
    TX_2_PORT = TX_2_PORT & (~(1 << (TX_2_PIN_1 % 8))) | (1 << (TX_2_PIN_2 % 8));
    next += HALF_PERIOD;
    while ((time = micros() - beginning) < next)
      ;
  }

  // Wait for end of cycle
  while (micros() - beginning < CYCLE)
    ;
}

{'fraction_non_alphanumeric': 0.13835920177383593, 'fraction_numerical': 0.05365853658536585, 'mean_word_length': 2.957894736842105, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5264089', 'n_tokens_mistral': 992, 'n_tokens_neox': 904, 'n_words': 241}