• This is a working example I have come up with with your help, maybe it's of any use to others.

    /*
    
    Example of an Espruino Object that fires an event when the button on pin D17 is pressed.
    
    */
    
    var P8 = {
      init : function(){
        setWatch(function(){
          P8.emit("button","D17");
        },D17 ,{ repeat:true,debounce:25 }
        );
      }
    }; // end of P8 Object
    
    // ============================= test of P8 object  ===============
    
    P8.init();
    
    
    P8.on('button', function(btn){ print("Button",btn, "press detected");});
    

    Output of the script when the button is pressed:
    Button D17 press detected

    In this example the init function needs to be called at start of the main script. Not sure if there is a way to move this init into the Object, but this works for me.

About

Avatar for gerardwr @gerardwr started