Flashing lights Try 4 not working #201
Unanswered
espruino-discuss
asked this question in
JavaScript
Replies: 1 comment
-
Posted at 2014-02-12 by @gfwilliams Hi. It seems there's a bug in the interpreter that causes It must have crept in recently because that code did work when I wrote it. I've made an issue for it and I'll try and fix it today I hope: espruino/Espruino#233 In the mean time, a simple change of order will help to fix it:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-02-12 by NightlyNexus
I am following the example in Try 4. I entered
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.
Beta Was this translation helpful? Give feedback.
All reactions