at first I use a KY-032 infrared sensor detects when a cap passes through the basket.
this modules the infra-red LED (set to 38 kHz), and has an IR demodulator (at 38 kHz).
I though this would be less noise prone, particularly from external IR sources.
turns out it is a lot more.
I tested will the cap reflecting the IR, but this is sometimes to short, and the demodulator might not detect it.
I tested with the cap breaking the barrier, but the IR demodulator doesn't allow continuous IR burst detection and has a hard time detecting when it is broken and restarted.
in the end, a simple LED on and photo-detector to create a barrier is super simple and efficient.
There are two firmware images: `bootloader` and `application`.
The `bootloader` image allows to flash the `application` over USB using the DFU protocol.
The `bootloader` is started first and immediately jumps to the `application` if it is valid and the DFU mode is not forced (i.e. by pressing the user button on the board or requesting a DFU detach in the `application`).
The simplest way do flash the `bootloader` image is using the embedded bootloader.
By pressing the BOOT0 button (setting the pin low) while powering or resetting the device, the micro-controller boot its embedded UART/USB DFU bootloader.
Connect a USB cable and run `rake dfu_bootloader`.
Once the `bootloader` is flashed, it is possible to flash the `application` over USB using the DFU protocol by running `rake flash` (equivalent to `rake dfu_application`.
Note: I use my own DFU bootloader instead of the embedded bootloader because I was not able to start the embedded USB DFU bootloader from the application.
The images can also be flash using SWD (Serial Wire Debug) in case the firmware gets stuck and does not provide USB functionalities.
For that you need an SWD adapter.
The `Makefile` uses a ST-Link V2 programmer along OpenOCD software (default), or Black Magic Probe.