From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
02-10-2020 01:13 PM - edited 02-10-2020 01:32 PM
Hey!
I am currently trying to program a dice using a random number generator. I have programmed it to light up
1 LED when showing 0
2 LEDs when showing 1
3 LEDs when showing 2
4 LEDs when showing 3
5 LEDs when showing 4
6 LEDs when showing 5
The number generating part of the program works good. The problem happens when it is supposed to light up the LEDs. Instead of lighting up multiple LEDs it only lights up one.
For example: The number generator generates the number 4, in this case it is supposed to light up 5 LEDs. But instead it only lights up one LED. Sometimes it doesn't even light up at all and sometimes it lights up different LEDs that show the wrong number.
This program used to work perfectly before but i did some small changes, after that it stopped working. I have also tried resetting the changes but I still can't get it working as I don't know what broke it.
All help is apprecieted!
I have attached a screenshot of the program.
02-10-2020 01:46 PM - edited 02-10-2020 01:47 PM
Hi GG,
the problem is called race condition - due to heavy overuse of local variables!
Hints:
Use an integer datatype for your numeric value.
Use one (1) case structure to define your boolean values.
Even better: use an array constant to define your booleans and a simple IndexArray function based on your numeric value!
When you need more help just search this forum, your problem is a typical exercise for LabVIEW beginners…
02-10-2020 02:21 PM - edited 02-10-2020 02:40 PM
Attach your actual code instead of a truncated picture.
@GG00 wrote:
This program used to work perfectly before but i did some small changes, after that it stopped working. I have also tried resetting the changes but I still can't get it working as I don't know what broke it.
The problem with race condition is that they are unpredictable and it is possible that it works correctly by chance but every edit (or undo) will cause a recompile and change.
I agree that an array of booleans is probably a better choice, but what you can try now to get it working quickly are two tiny changes:
See how far you get...
02-10-2020 02:49 PM
Here is something to get you started. It won't be easy for a beginner to put it together from a picture and to fully understand the reason for each code items (Yes, they all have a purpose!), so this is a good learning experience. Make sure to understand the code fully! Also note that your teacher reads this forum, so don't cheat and copy it blindly. It would be trivial to change it to output 6 scalar LEDs at the end. Try it!
It also teaches you that a simple problems only need simple code. If you can describe the problem in a few short sentences but it takes you a screen-full of LabVIEW code, you should immediately suspect that you are doing something wrong. 😄