Surely, you will possess one or more pocket calculators and do not need another one, so the main emphasis of this article is to give a simplified example on how to create a so-called Finite-State-Machine.
The goal was to implement a pocket calculator as a well-known example, driven by an Arduino, but controlled over the ethernet by means of a web browser.
As Finite State Machines were introduced in 1955 by George H. Mealy, it is not surprising to find dozens of books on this matter, some of which are very hard to read. Out there are a lot of good books about FSM and also about web servers. But rarely both of them are combined.
In this example a web page showing the keys of a very simple pocket calculator will send each click to the FSM which performs the appropriate action and send a new web page to the client. It also could perform actions on the Arduino itself or handle any data read by some sensors.
To access the virtual pocket calculator just enter 192.168.2.42:8080 in your web browser (the first digits might be different dependig on your LAN). In order to access it online you have to provide port forwarding and dyndns service. You need to check your router's manual. It might look like this:
Some professionals would tell you this is more than simplified, and they are right. But we are not doing rocket science or producing medical instruments, right?
The calculator implemented here is far from being perfect. It does not handle overflow, division by zero, floating-point numbers, not even simple chains of calculation like 1+2+3 or algebraic calculation like 1+2*3 or brackets.
In case you want to extend this example keep in mind that in this case all the input symbols are equal to the key labels, meaning they consist of only one character. So, if you want keys labelled “sin” or “exp” you have to distinguish between symbols and labels.
Comments