## 2 Materials and Methods
The advantage of using Firmata consists of the possibility of using another microcontroller compatible with Firmata. PN2 ARDUINO extends PNEditor with many features. For Petri nets modeling, there is a possibility of adding time delays to transitions, and capacity for places. Also, automatic mode of transitions firing was added for automatic control purposes as only manual mode is available in PNEditor. In PN2 ARDUINO, a new module is added to PNEditor to enable communication with the compatible microcontroller. This module consists of two parts. The first part establishes connection with the microcontroller by setting the COM port where the microcontroller is connected. The second part provides a capability of adding Arduino components to Petri net places and transitions. The following types of Arduino components are supported: digital input and output, analog input, servo control, PWM (pulse-width modulation) output, message sending, and custom SYSEX message [26] sending. Originally, SYSEX (System Exclusive) messages are model-specific messages for setting various parameters of a MIDI device. The idea for SYSEX is to have a second command space using the first byte after the SYSEX Start byte. The key difference is that the data can be of any size, rather than just 1 or 2 bytes for standard MIDI messages. The use-case diagram of the developed SW tool is depicted in Figure 3, and the class diagram is shown in Figure 4.  
As stated, transitions and places can be associated with Arduino components. Digital and analog inputs serve as enabling conditions for Petri net transitions. Digital and PWM outputs and messages are used as executors of the respective actions. The interesting functionality is the capability of sending custom SYSEX messages. The user must enter a SYSEX command (0x00-0x0F) and optionally also the content of the message. The message is sent when the token comes to the place or when the transition is fired. SYSEX messages have been used e.g., in the proposed hybrid control example in the last section of this article. Here, the SYSEX message notifies the microcontroller that a different PID control algorithm is to be used. Then the PID algorithm is switched, and the controlled system remains stable. A main window of PN2 ARDUINO consists of a quick menu, main menu, canvas for Petri net modeling and log console. PN2 ARDUINO supports two modes--a design mode and a control mode, the control mode can be manual or automatic. \begin{table}
\begin{tabular}{l l} \hline \hline
**Petri Net Logic in PC** & **Petri Net Logic in Microcontroller** \\ \hline limited capability of real-time control & real-time control \\ \hline much more computation and memory resources & limited computation and memory resources \\ available & \\ \hline code in microcontroller does not need recompiling & during development repeated compiling is needed \\ \hline PC must be still online & independence of control unit \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Comparison of two concepts of system control using Petri nets. First, it is necessary to initialize communication with Arduino (Setup board in the menu). Then it is possible to add Arduino component to the place or to the transition (Figure 5). The example of analog input is shown in Figure 6.  
Time policy is also supported--it is possible to add time delay to the transitions which can be deterministic or stochastic. Using a deterministic time policy, the delay is entered by user during Petri net modeling as a specific integer that represents the duration of the delay. After the specified delay, the transition is fired. The stochastic time policy is based on entering two time frames. The first represents the shortest possible delay and the second represents the longest possible delay. These time frames are also entered directly by user during modeling process. The specific value of the delay is determined randomly in the range of this entered interval. During enabling a transition that has a defined delay, tokens from all entry places are consumed first.