What about having this global function uploaded? It will toggle any pin:
function toggle(pin) { pin.write(pin, !pin.read(); }
To be on the safe side - NOT make an input pin an output pin - use this code:
function toggle(pin) { if (pin.getMode().indexOf("output") > -1) { pin.write(pin, !pin.read(); } }
...and prototype-based-object-oriented, upload this expression, which will give you the .toggle():
Pin.prototype.toggle = function(){ if (pin.getMode().indexOf("output") > -1) { pin.write(pin, !pin.read(); } }
@allObjects started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
What about having this global function uploaded? It will toggle any pin:
To be on the safe side - NOT make an input pin an output pin - use this code:
...and prototype-based-object-oriented, upload this expression, which will give you the .toggle():