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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple State Machine template to build a simple calculator

Hi,

I need to build a simple calculator using the simple state machine template in Labview.  The requirements are 

  • Each calculation will be a separate state in the state machine.
  • The user will choose one of the following calculations: add, subtract, multiply, divide.
  • The user will input two numbers A and B with a horizontal pointer slide control.
  • Provide an enumerated control on the front panel window for the user to select the operation.

I have seen different posts about creating a simple "old fashioned" calculator and I have tried following their procedure, but because the operations are enumerated controlled and the values are horizontal sliders I don't know how to set up my block diagram.  Any help would be much appreciated.

0 Kudos
Message 1 of 5
(2,726 Views)

So you're going to have two sliders for the numbers, then four buttons.  When pressed, each button will execute a state.  When you look for examples, don't just look for calculator examples, look for state machine examples, period.  On any LabVIEW VI, or the startup screen, Help --> Find Examples is a great place to start.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 5
(2,711 Views)

Your requirements are much simpler than needed for a "state machine". You really don't require one! You just have two numeric inputs, a mode selector (enum with four items), and a result display. Whenever any of the controls change, the result needs to be recalculated. There are no "states" that need to be communicated across iterations, for example. You can do it polling or using an event structure.

 

If your teacher wants a "state machine", maybe it should be explained why. Seems to just complicate things unnecessarily... 😉

0 Kudos
Message 3 of 5
(2,647 Views)

Perhaps there is only one horizontal slider intended? The original post was a bit unclear - it mentions a slider, then not knowing what to do about the sliders.

 

If you have only one slider, and an "Equals" button as well as the methods, then you can imagine there might be some "state" in this system (i.e. the result so far of previous operations or the previously entered value, depending on if this is the first operation used or they are chained together).

 

It's still a little bit of a stretch to require a state machine, but at that point you do have some history requirements.

Of course, it could be implemented with an array of inputs including methods and then a parsing operation when "Equals" is pressed, and so no states would be needed (just an Event Structure and a shift register, perhaps with array of strings) but this would be less efficient.

 

If you allow parenthesis, things become more complicated but that sounds outside of the original scope...


GCentral
0 Kudos
Message 4 of 5
(2,627 Views)

@cbutcher wrote:

The original post was a bit unclear - it mentions a slider, then not knowing what to do about the sliders.


Well, it could be a single slide control with two sliders ... 😉

 

altenbach_0-1584291319606.png

 

 

(Of course, the order matters for subtract and divide, so they need to be identified in some way, e.g. by color)

 

 

0 Kudos
Message 5 of 5
(2,615 Views)