Recently I converted my carbon frame road bike into an electric bicycle with a motorised front hub. A significant challenge was to devise a method of ensuring that the carbon forks are strong enough to handle the motor torque forces. However that’s another story.
Apart from that, the setup is relatively simple with no special sensors other than speed sensing via the hub motor. So I decided to implement very simple controls, essentially a momentary motor on/off switch (more than one) on the handlebars, with low, medium, high speed control, set using a rotary switch. So when the on/off switch is depressed the motor is run at whatever speed is set on the rotary switch.
This setup worked pretty well but it was annoying to have to keep one of the two on/off buttons depressed to keep the motor running. So I decided to modify the control unit to latch the motor on when the on/off button was pressed for more than a few seconds, switching the motor off by a further brief button press. The little control unit to achieve that is described here.
Essentially this is a small PCB with a Microchip Attiny85 implementing the logic. This is connected to the bike’s brushless motor control unit throttle control. The throttle control provides 3 wires, positive supply (around 4.4 volts), ground and control voltage in. The motor speed increases as the control voltage is increased from around 2 to 4 volts.
The Attiny85 is configured to output the control voltage via a pulse width modulated pin. A resistor and capacitor is used to turn the pulse output into an (approximately) DC voltage, whose level is set by the width of the pulses. A rotary switch is used to pull one of three different pins of the Attiny85 low, which is used to select the pulse width hence control voltage output, to achieve a low, medium, or high motor speed.
The zip file contains Autodesk Eagle schematic and board files for the small, double sided PCB as well as the Attiny85 firmware as an Arduino sketch.
The Attiny85 needs to be running at 8MHz

Ron,
I see your comments to my comments (and other comments, of course) and noted your video of a recent submission, and thought to contact you more directly. To use this particular link legitimately I will make a comment about its subject: What a nice little block of compact code. I learnt my first coding in FORTRAN and it has taken me 60 years to reach my current state of partial ignorance. Sparse is good! My latest projects use pro trinket, I admire trinket MO but I keep my code well within the pro-trinket bounds, and anyhow in the aircraft (turbo experimental controller and altitude compensator) the voltage tolerance is one component less, and the additional pins are useful. Two pressure sensors (boost and altitude) oled display, rheostat for input tweaking, button to cycle through the menu of which parameters the rheostat changes, PWM link to MOSFET driver for the MAC bleed valve – there’s more but you know all this stuff too. I have some other economic tweaks on the go, but don’t want to trouble you unless you are interested. Most warmly, P