Pin.prototype.startFlashing = function(period) {
if (Pin.intervals===undefined) Pin.intervals = [];
if (Pin.intervals[this]) clearInterval(Pin.intervals[this]);
var on = false;
var pin = this;
Pin.intervals[this] = setInterval(function() {
on = !on;
digitalWrite(pin, on);
}, period);
};
But, when I run "LED1.startFlashing(1000);" in the terminal, I get "ERROR: Invalid pin!"
"console.log(pin);" prints "=undefined" so something is very wrong.
However, when I run "var light = LED1;" and then "light.startFlashing(1000);" I get the expected behavior.
What is going on here? I am a Java developer and don't use JS that much, so I may be misunderstanding something simple.
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.
I am following the example in Try 4. I entered
But, when I run "LED1.startFlashing(1000);" in the terminal, I get "ERROR: Invalid pin!"
"console.log(pin);" prints "=undefined" so something is very wrong.
However, when I run "var light = LED1;" and then "light.startFlashing(1000);" I get the expected behavior.
What is going on here? I am a Java developer and don't use JS that much, so I may be misunderstanding something simple.