When I developed this asset, I really had in mind the optimization as well as giving the power to the user to optimize the code as he wishes. That's the main difference between Uduino and the other existing assets.
Concretely, it means there are several of communicating with the Arduino Board:
Uduino features some advanced settings that you can manipulate to improve the performances of your game. These settings are available on the Editor under the Advanced
dropdown.
Remember, if your game runs at 60 FPS, it means there is one Frame every 16 ms. By default the value of "Thread Frequency" is 16ms: Every 16 ms, the parallel thread will read and write some data to the Arduino board, then perform an action on the main Update loop of the game.
Every time you call a Uduino function (e.g. digitalWrite()
), the command will be stored in a temporary buffer, waiting for the beginning of the new "UduinoThread" cycle to be sent over or to trigger an action on the Update()
loop.
To skip the buffer and only send one information per cycle, you can toggle the Skip Queue boolean.
Every end of Update()
loop, I could "empty" the send buffer (there is the option to clear everything but not to send everything at once). I chose not implement that, however, in a near future, I'm considering adding this as an additional option.
If you send too many commands during the same Update()
loop, the "write buffer" is going to be filled. And if you don't let enough time for the buffer to be sent to the Arduino board, for the user it will appear that some information is not sent properly to the board. For instance, the code here will most likely cause problems without optimization.
void Update() {
UduinoManager.Instance.analogWrite(3, 155);
UduinoManager.Instance.analogWrite(5, 30);
UduinoManager.Instance.analogWrite(6, 215);
UduinoManager.Instance.analogWrite(9, 0);
UduinoManager.Instance.analogWrite(11, 100);
}
Hopefully, it's pretty easy to change Uduino settings to make it work!
For an optimized code, using the default Uduino sketch is not the best solution. The best method is to develop your own commands sets using the advanced features of Uduino.
I recommend you to follow the tutorials on advanced data reading, advanced data writing, or other examples.