Page 1 of 1

Phidget led 64 - Setting a channel

Posted: Mon Nov 05, 2018 6:34 pm
by gallantoss
How do I set more than one channel in javascript, using the phidget led 64?

sensor = new jPhidget22.DigitalOutput();
sensor.setDeviceSerialNumber(389142);

for(let i = 0 ; i <=1 ; i++){

sensor.setChannel(i);


}

This is what I tried so far...

Thank you!

Re: Phidget led 64 - Setting a channel

Posted: Tue Nov 06, 2018 9:08 am
by mparadis
You need to create a separate DigitalOutput object for each channel you want to have open. So, you could do something like this:

Code: Select all

sensor0 = new jPhidget22.DigitalOutput();
sensor1 = new jPhidget22.DigitalOutput();
sensor0.setDeviceSerialNumber(389142);
sensor1.setDeviceSerialNumber(389142);
sensor0.setChannel(0);
sensor1.setChannel(1);
Of course, this will get tedious quickly if you want to do it for all 64 channels, so you might want to use an array and a loop instead:

Code: Select all

var leds = [];

for(i = 0; i < 64; i++) {

	ch = new jPhidget22.DigitalOutput();
	ch.setDeviceSerialNumber(389142);
	ch.setChannel(i);
	leds.push(ch);
}

From then on you can access the digital output with leds. You'll have to create a similar for loop when you open, close, or set any property that you want on all 64 outputs.