You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • Hi Sam!

    That's a great idea - I've been meaning to try something like that.

    If you really are using a Pico, D0 is not a valid pin (https://www.espruino.com/Pico#pinout). Which pin did you think you were connecting to?

    If I'm reading your post right, it's really the setWatch that's not firing reliably? So you could remove all your code and just do

    const sensor =D0;
    pinMode(sensor, 'input_pullup');
    setWatch(function(e) {
      LED.write(e.state);
    }, sensor, {edge:"both",  repeat:true});
    

    And see what happens? Having the debounce probably won't help you.

    The 40k internal vs 2k resistance sounds like it would be fine. Are you sure that you have your LED attached to the light sensor in such a way that no light from anywhere else is getting in? If it was, it could mean the light sensor always have a reading that there was light.

    @Robin :

    The pulses of LEDs in UK electricity meters are quite fast - polling every 0.5 seconds won't do it. You'd need to do it 1000 times a sec to be even remotely sure.

    Could sensor need the same? (e.g. is const sensor actually 0xD0 "D0" or D0)

    No, afraid not. Like in all of the Espruino examples, you just use a pin name as-is, eg D0 - not quoted or a hex number.

About

Avatar for Gordon @Gordon started