You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • @allObjects yes, you could go all out trying to use the built-in hardware on 8 channels simultaneously to get really accurate results... Because you're just measuring pulse lengths you can use @ClearMemory041063's code (or this for the Pico) as is (without having to have anything running on interrupt), because you don't care if you miss a reading or not (the latest value will always be in the register).

    OR you could just do what the Arduino code does, which only needs 4 lines of code and works on any pin:

    function getLight(pin) {
      var c=0;
      pin.set();
      while(pin.read())c++;
      return c;
    }
    

    I reckon that would work relatively well - you might get one or two glitchy readings but on the whole it'd be good enough.

About

Avatar for Gordon @Gordon started