Phidget led 64 - Setting a channel

Supporting Browser-based Javascript and Node.js
Post Reply
gallantoss
Fresh meat
Posts: 2
Joined: Mon Oct 29, 2018 7:29 am
Contact:

Phidget led 64 - Setting a channel

Post 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!
User avatar
mparadis
Site Admin
Posts: 959
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: Phidget led 64 - Setting a channel

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests