I am trying to change a design that I have on a PCB (Raspberry Pi 4/5) hat from a photoresistor to a phototransistor. The RPi has only digital input and no ADC inputs. So I need to transform the values from analog to a timed based system that I can detect.
I am using a capacitor as a "battery" that I fill with a GPIO signal (3.3V) and then time how long it takes to "deplete" (technically to 1.6V) and this gives me a very usable value for the light intensity. I don't need anything more precise than that (It's used to dim the screen gradually in low light conditions and so not an on/off switch). It works very well with the photoresistor, but it's not an SMD component and can't easily (cheaply) be mass produced.
I am tying to move to a phototransistor. However, those give a variable amount of current and not resistance. I am trying to find a suitable circuit that translates that to a similar design (hard to redesign the whole layout) and I don't want to use another IC for A/D conversion as it's still hard to read with a single digit pin.
Here's a circuit I came up with, but I'm not sure it will work. The idea is that once the capacitor is filled, the rate of decrease is changed by how much current the phototransistor emits. As there are significant costs to make test PCBs to see it the design is correct, I would love some expert advice on this design or anything similar using only passive components.

simulate this circuit – Schematic created using CircuitLab
My main concern is knowing if this circuit will "drain" the capacitor correctly once the GPIO pin goes to input mode (like my photoresistor design).
If you know a better design, I'm also all ears.


