Tour Easy Running Lights: Firmware

The optoisolator carrying the Bafang controller’s LIGHT signal pulls Pin 2 down to turn the LED on constantly for night riding:

    if (!Morser.continueSending())
        if (digitalRead(PIN_LIGHTMODE) == HIGH)
            Morser.startSending();
        else
            digitalWrite(PIN_OUTPUT,HIGH);      // constantly turn on in headlight mode

That’s the entirety of the program’s loop() function, so there’s not much to the firmware.

Imagine that: a whole computer devoted to sampling an input bit a zillion times a second and persistently setting an output bit:

Tour Easy Running Light - Arduino view
Tour Easy Running Light – Arduino view

The Morse output to the rear is now “s” rather than “i” for more blinkiness, but I doubt anybody will ever notice.

The next time I raise the hood on this thing, I’ll add a digital input to select FRONT or REAR mode to get me out of having to remember which hardware goes where.

The Arduino source code as a GitHub Gist:

// Tour Easy Running Light
// Ed Nisley - KE4ZNU
// September 2021
// 2023-03 preprocessorize for front/rear lights
// https://github.com/markfickett/arduinomorse
#include <morse.h>
// Bafang headlight output pulls pin low
#define PIN_LIGHTMODE 2
#define PIN_OUTPUT 13
#define FRONT
#if defined(FRONT)
#define BLINKS "b e "
#define POLARITY false
#elif defined(REAR)
#define BLINKS "s "
#define POLARITY true
#else
#error "Needs FRONT or REAR"
#endif
// second param: true = active low output
LEDMorseSender Morser(PIN_OUTPUT,POLARITY,(float)10.0);
void setup()
{
pinMode(PIN_LIGHTMODE,INPUT_PULLUP);
Morser.setup();
Morser.setMessage(String("qst de ke4znu "));
Morser.sendBlocking();
Morser.setSpeed(75);
Morser.setMessage(String(BLINKS));
}
void loop()
{
if (!Morser.continueSending())
if (digitalRead(PIN_LIGHTMODE) == HIGH)
Morser.startSending();
else
digitalWrite(PIN_OUTPUT,HIGH); // constantly turn on in headlight mode
}

2 thoughts on “Tour Easy Running Lights: Firmware

  1. As I was explaining a water meter:

    ” . . . so 10,000 times a second, the processor looks for a change in the line from each of the sensors, if there is a change it adds 1 to the pulse count . . . ”

    (incredulous reply) It does that? 10,000 times a second? Always? Right now?

    Cheap computers – – ever so patient and prolific. I hope when the AI overlords take control they have mercy on us embedded programmers after our subjecting their smaller brethren to lives of endless repetitive torment.

    1. Having read Saberhagen’s Berserker stories in my formative years, I have absolutely no illusions whatsoever.

      Somebody, somewhere, somewhen, will make that one little mistake and, after that, there will be no coming back.

Comments are closed.