LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Shifting bits in an array

Solved!
Go to solution

Hello,

 

I am a student Electromechanics in Belgium and I am making a simulation of an explosion with 48 leds for my final project.

In the attachment you can see the program I already wrote. I think it can be done easier but I don't know how.

I splitted the 48 leds into 2 arrays, with in each array 24 leds.

If you see the program you will understand :smileyhappy: Actually the best way to make this is to shift bits, but I don't know how it can be done in LabVIEW.

I will have to expand my program so it would be nice if I could just symplify this to get a better overview.

 

So what I would like to know, can I shift "bits" like you can see the leds burning in following VI?

It has to be possible to set the number of bits that are "1", and the speed of the shifting.

3 bits at the time:

1) 1110 0000 0000

2) 0111 0000 0000

3) 0011 1000 0000

4) 0001 1100 0000

 

5bits at the time:

1) 1111 1000 0000

2) 0111 1100 0000

3) 0011 1110 0000

4) 0001 1111 0000

 

 

Thanks

0 Kudos
Message 1 of 13
(5,409 Views)
0 Kudos
Message 2 of 13
(5,400 Views)

I know, but the old one isn't correct.

I tried to delete it but I don't know how..

0 Kudos
Message 3 of 13
(5,398 Views)

OK, so we're going to stay in here then? I posted a reply in the other to indicate the move.

 

Your VI is hard to follow. You have local variables EVERYWHERE. You are clearly a text-based programmer who is trying to write LabVIEW code as if it were C. Skipping what your VI is actually doing, it sounds to me like you need to use Rotate 1D Array.

0 Kudos
Message 4 of 13
(5,393 Views)

The trick here is to pick a data type to represent the numbers. To make it generic, use an array of Booleans, and wire it as an input to a subVI. The next trick is to shift the Booleans without overwriting them, so you'll want to make a copy of the array of Booleans. In LabVIEW terms, that simply means making a fork in the wire which is the array of Booleans. Now use a For Loop with a shift register to move the data from one array of Booleans to the other.

 

If this does not make sense I'll check this thread this evening and give you a sample VI.

0 Kudos
Message 5 of 13
(5,385 Views)

Thank you smercurio, thats what I need!

Excuse me for my messy programming, hopefully I can clean up my Block diagram with this function.

But how else can I use all the variables for a multiple times without using local variables and still keep it easy to follow? 

Bmihura, I tried to follow your explenation, but unfortunately did not succes building it.

If it's possible, can you make a little VI to show the principle on which I can build up the rest of the program?

There is no rush for it, I have many other things I still have to find out in LabVIEW for my project so.

 

Thanks for your help!

0 Kudos
Message 6 of 13
(5,372 Views)

@Stef_vl wrote:

Thank you smercurio, thats what I need!

Excuse me for my messy programming, hopefully I can clean up my Block diagram with this function.

But how else can I use all the variables for a multiple times without using local variables and still keep it easy to follow? 

Bmihura, I tried to follow your explenation, but unfortunately did not succes building it.

If it's possible, can you make a little VI to show the principle on which I can build up the rest of the program?

There is no rush for it, I have many other things I still have to find out in LabVIEW for my project so.

 

Thanks for your help!


Try using a state machine to control your application. Your data would flow through the state machine as wires. No need for local/global variables. LabVIEW is a data flow language. It will help your LabVIEW coding if you take some time to understand exactly what that means and how to use it.

 

Additionally you could look at using LVOOP (LabVIEW OOP) and allow your objects to contain and operate on the data. Of course good design dictates that the methods and data in an object should be related.

 

As a side note, I find it very difficult to look through code such as the VI you posted. If I can't see the basic logic one a single screen I find it very difficult to follow and understand. A good rule of thumb is that a block diagram should fit on a single screen. If you must scroll it should be limited to a single direction. Even in this case you should be able to display enough of the code to fully understand that section. Sequence structures should generally be avoided. See my comment above as to how you can avoid using them. Don't be afraid to create and use subVIs. You wouldn't write a C program with all the code in a single procedure so why consider this an acceptable thing in LabVIEW (all the code in one VI)?



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 7 of 13
(5,355 Views)

Attached is a simple VI that shifts bits in a Boolean array. You could write a similar one for shifting bits in an integer, but this is more generic.

0 Kudos
Message 8 of 13
(5,331 Views)

bmihura, can you please upload the VI for a 10.0 version? My LabVIEW is to old to open your version.

Thank you for the help!

Mark, I will try to use your advise, many thanks!

0 Kudos
Message 9 of 13
(5,318 Views)

Version 10, attached.

Message 10 of 13
(5,307 Views)