Newby in Phidget programming in Javascript and Node JS
Posted: Tue Jul 09, 2019 10:41 am
Hi
I have the code I am playing with:
The code are demostrating an switch event with Johnny-Five an phidget. The code for opening the diff. channel are stored in a object "LEDBoardObj". The instance itself is in that obj on key board1 --> chInstance0/1/2/3/4/5 ...... !
So when swith on at my swith the led it should be light and should be closed when the with is off. I have one green led and one red. My goal is switch = on, led green is on. When switch = off a red led is on and the green led is off. Like a blinking light but with two leds
I have read about a close function but where am I need placing it in both the vs1_13.on('open'/'close', functions ... to getting it to work?
If you are going to need more info I can share it, no problem!
Best regards Fredrik
I have the code I am playing with:
Code: Select all
let vs1_13 = new jFive.Switch(12);
vs1_13.on('open', function () {
console.log('vs1_13 on');
//LED on
LEDBoardObj.board1.chInstance0.open().then(function () {
// code to execute after open succeeds
console.log('Utgång 0 - Öpppen');
LEDBoardObj.board1.chInstance0.setDutyCycle(dimValue);
}).catch(function (err) {
// code to execute if open fails
console.log('Utgång 0 - Ej öppen');
});
// Status setting
// FlightSim setting
});
vs1_13.on('close', function () {
console.log('vs1_13 off');
//LED on
LEDBoardObj.board1.chInstance1.open().then(function () {
// code to execute after open succeeds
console.log('Utgång 0 - Öppen');
LEDBoardObj.board1.chInstance1.setDutyCycle(dimValue);
}).catch(function (err) {
// code to execute if open fails
console.log('Utgång 0 - Ej öppen');
});
// Status setting
// FlightSim setting
});
So when swith on at my swith the led it should be light and should be closed when the with is off. I have one green led and one red. My goal is switch = on, led green is on. When switch = off a red led is on and the green led is off. Like a blinking light but with two leds
I have read about a close function but where am I need placing it in both the vs1_13.on('open'/'close', functions ... to getting it to work?
If you are going to need more info I can share it, no problem!
Best regards Fredrik