03-04-2024 09:35 AM
So i want to make a vi that generates all the numbers of fibonacci. It can't go higher than a given number by the user of the program. The program i made works, but everytime i want to use it i have to click the arrow. Is there a way to avoid this?
Solved! Go to Solution.
03-04-2024 09:39 AM
@corned wrote:
So i want to make a vi that generates all the numbers of fibonacci. It can't go higher than a given number by the user of the program. The program i made works, but everytime i want to use it i have to click the arrow. Is there a way to avoid this?
Turn it into a subVI.
Put a while loop around it.
You probably want an event structure too, to trigger the call.
This is pretty basic. You might want to do some (free) tutorials.
03-04-2024 10:40 AM
@corned wrote:
So i want to make a vi that generates all the numbers of fibonacci. ?
Since the series has an infinite number of elements, it is impossible to generate all of them. Do you have an input for an upper limit or number of elements?
@corned wrote:
The program i made works, but everytime i want to use it i have to click the arrow. Is there a way to avoid this?
You simply need to make it into a toplevel VI with a while loop, a reasonable loop rate (or an event structure) and recalculate the series whenever the input changes. Think "state machine".
Ultimately, you can build it onto a standalone executable (or configure it to run when opened, not really recommended).
03-05-2024 05:56 AM
Adding to the previous answers; Are you just wanting to reread the results at a later time? If so, it's easy to write the result to a text file and simple look there, e.g. Input in the 1st column and the fibonacci numer in the 2nd.
03-05-2024 06:45 AM
I have to make a program that gives all the numbers of fibonacci lower than a given number by the user. It works great but the stop button is not working. How do i fix this?
03-05-2024 07:10 AM
Welcome to the LabVIEW Forum.
As a new user of LabVIEW, you might not know that if you post code using LabVIEW 2022, the people with the most experience with LabVIEW might not have purchase the "latest version" (which, admittedly, 2022 is not), and won't be able to open and look at your code. But you can open your routine, go to the File menu, and "Save for Previous Version". Almost all of the "experts" will be able to read LabVIEW 2019 or 2021.
So I'll make some "guesses" at your problem with the Stop button. I'm assuming you are using the one on the Boolean palette for the Front Panel. Boolean controls have a "mechanical action". Some (like the Push Button and Toggle Switches) are "Switch when Pressed" -- you change them, and they "stay changed" until you change them again. However, the Rectangular ones (like "Stop" and "OK") are "Latch when Released" -- this mean they "stick" until you read them, then they revert to their default value. So if you put a Stop button on your Block Diagram, every time you read it, the mechanical action will reset its value to its default value (which is False) after it is read.
This is not a "bug", it is a Feature. If you post your code in LabVIEW 2019 (and none of my colleagues on the Forum has answered you yet), I'll suggest how you can "fix" the Stop Button problem.
Bob Schor
P.S. -- another sometimes-useful Mechanical Action is "Switch until Released" -- this makes the "Push Button" really behave like a buzzer Push Button -- as long as you are pushing it, it is "True", but when you lift your finger off it, it switches back to "False". These kinds of Mechanical Actions are designed for creating "responsive Front Panels", but if you are unaware of these "actions", can cause confusion when you are trying to use them as ordinary Boolean (True-false) variables.
03-05-2024 07:13 AM - edited 03-05-2024 07:14 AM
The stop doesn't work, because the event structure stalls data flow.
Add an event case for the stop button's value change event, and wire a Boolean true in it to the loop's stop criterium.
Also, put the max value outside the loop. It's just cleaner.
Groeten, Wiebe.
03-05-2024 10:17 AM
Let's have a look at your VI:
03-05-2024 10:33 AM - edited 03-05-2024 11:12 AM
See if this can give you some ideas. Note that if you "tap" the wire before the addition, you correctly get the zero as first element and the last element that is smaller than the max value entered. No need to trim later. Your stop button must be latch action. I have no idea why you would change that.
03-05-2024 11:11 AM - edited 03-05-2024 01:51 PM
Be aware that for very large inputs the while loop will never stop due to the magic of integer math. To protect from rollover, you need to check as follows:
Now is is guaranteed to complete the loop when the numbers wrap and you can get all 94 elements that fit into U64 instantly (Max=18446744073709551615)
To go higher, you would need to implement bignum math.