LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Using LEDs as a Control

Hi all

 

I want to control 24 digital outputs of a certain DAQ card. For controlling , i want to
use 24 LEDs as a control from DO_0 to DO_23. The digital output write function of the
DAQ card outputs that value, which is stored in its BUFFER having data type 'BYTE' .
The maximum value on one location of the BUFFER is 255 , which at a time writes 8 digital outputs.
So it means that my BUFFER will have only 3 locations to write to the 24 digital outputs.

 

My question is that

 

How can i store the values to the 3 locations of the BUFFER according to the Status of 24


LEDS from DO_0 to DO_23 ? Such that the corresponding decimal value of " DO_0 to DO_7 " stores on

 
the " ZERO LOCATION OF BUFFER i-e BUFFER[0] " and the corresponding decimal value of


"DO_8 to DO_15" stores to the " FIRST LOCATION OF BUFFER i-e BUFFER[1] " and similarly


the corresponding decimal value of "DO_16 to DO_23" stores to the " SECOND LOCATION OF


BUFFER i-e BUFFER[2]" ?

 

Any help will be greatly appreciated

 

Regards

0 Kudos
Message 1 of 3
(2,984 Views)

You can easily accomplish this task in a loop using aan array of control IDs and some bit shifting to prepare the BYTE value.

 

Prepare an int array where to store the IDs of your leds (to be run only once at program start: control IDs do not vary at runtime):

 

int  leds[24];

leds[0] = PANEL_LED0;

leds[1] = PANEL_LED1;

...

leds[23] = PANEL_LED24;

 

 

Next each time you want to update the logic read values in a loop and prepare the value for the digital output:

 

int  i, val;

int  b0 = 0, b1 = 0, b2 = 0;

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

  GetCtrlVal (panelHandle, leds[i], &val);

  b0 += (val << i);

  GetCtrlVal (panelHandle, leds[i + 8], &val);

  b1 += (val << i);

  GetCtrlVal (panelHandle, leds[i + 16], &val);

  b3 += (val << i);

}

 

Now you have your values b0, b1 and b2 to write to the daq card.

 

(Code written by memory: may need some trimming or correction)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 3
(2,970 Views)

Roberto was a bit quicker than I was (no big surprise).  I took the same basic approach: array of control IDs, reading and bit shifting the LED values to form bytes.  I chose to update only the byte that was modified, not knowing your full application.

 

From a performance standpoint, I'm not sure there's much benefit to only reading the byte that was updated, but that's what I did.

From an application standpoint, I'm not sure you need to read the LEDs after each LED was pressed, but that's what I did.  For your final application, you may want to have one button to update the buffer, instead of updating it after every click on an LED.

 

Take a look at the attached sample program.  The user interface has a few bells and whistles you don't need, but it made for a good demonstration.

Message 3 of 3
(2,964 Views)