Vacuum Tube LEDs: Now With Morse Code

Adding Mark Fickett’s non-blocking Morse Arduino library turns the tubes into transmitters:

21HB5A on platter - orange green

21HB5A on platter – orange green

The plate cap LED blinks the message in orange, while both LEDs continue to slowly change color as before.

You define a Morse sender object (C++, yo!) by specifying its output pin and code speed in words per minute, dump a string into it, then call a continuation function fast enough to let it twiddle the output bit for each pulse. Obviously, the rate at which the callback happens determines the timing granularity.

However, setting a knockoff Neopixel to a given color requires more than just a binary signal on an output pin. The continuation function returns false when it’s done with the message, after which you can initialize and send another message. There’s no obvious (to me, anyhow) way to get timing information out of the code.

The easiest solution: called the Morse continuation function at the top of the main loop, read its output pin to determine when a dit or dah is active, then set the plate cap color accordingly:

LEDMorseSender Morse(PIN_MORSE, (float)MORSE_WPM);
...
Morse.setup();
Morse.setMessage(String("       cq cq cq de ke4znu       "));
PrevMorse = ThisMorse = digitalRead(PIN_MORSE);
...
if (!Morse.continueSending()) {
  Morse.startSending();
}
ThisMorse = digitalRead(PIN_MORSE);
...
if (ThisMorse) {             // if Morse output high, overlay
    strip.setPixelColor(PIXEL_MORSE,MorseColor);
}
PrevMorse = ThisMorse;
strip.show();               // send out precomputed colors
...
<<compute colors for next iteration as usual>>

I use the Entropy library to seed the PRNG, then pick three prime numbers for the sine wave periods (with an ugly hack to avoid matching periods):

uint32_t rn = Entropy.random();
...
randomSeed(rn);
...

Pixels[RED].Prime = PrimeList[random(sizeof(PrimeList))];

do {
  Pixels[GREEN].Prime = PrimeList[random(sizeof(PrimeList))];
} while (Pixels[RED].Prime == Pixels[GREEN].Prime);

do {
  Pixels[BLUE].Prime = PrimeList[random(sizeof(PrimeList))];
} while (Pixels[BLUE].Prime == Pixels[RED].Prime ||
        Pixels[BLUE].Prime == Pixels[GREEN].Prime);

printf("Primes: (%d,%d,%d)\r\n",Pixels[RED].Prime,Pixels[GREEN].Prime,Pixels[BLUE].Prime);

In the spirit of “Video or it didn’t happen”: YouTube!

The Arduino source code as a GitHub Gist:

Advertisements

,