Closed HarterHorst closed 2 years ago
Hi, you need to wait until the returned promise from the inputPin
method is resolved before you can call inputPin
again.
So your approach with the promise chain is basically right, but there are two issues:
1) you havn't declared the pin
variable.
2) When the callback of .then(...)
gets executed, pin
will always be 8
.
Try running this code snippet:
var promChain = Promise.resolve();
for(pin=0; pin<8; pin++){
promChain = promChain.then(function(){
console.log(pin);
//return pcf.inputPin(pin, false);
});
}
This will log eight times 8
.
To get the correct value for pin
you need declare it as a local variable in the for
loop using the let
keyword like this:
let promChain = Promise.resolve();
for(let pin=0; pin<8; pin++){
promChain = promChain.then(function () {
console.log(pin);
//return pcf.inputPin(pin, false);
});
}
Yes, that was the problem. Thanks for that. I should check the basics next time. for loops are not so difficult.
Hi, i have an issue with the library during the process of setting inputPin for multiple pins. I have tried to set the pins via a for loop but that leads to the error message below. Then i tried to set them separately which brought the same result.
Error message is:
Regardless of the error message, the code works. But this does not feel good.
When I only set one pin (e.g. PIN 0) I'm not getting any error message.
Any ideas?
Code