During my first researches on the curltable I thought it would be nice to have some functions controlled by external elements such as potentiometers, buttons or sliders. So I gave it a try and used my Arduino and the serialPort class for communication to the board. What I tried was to control the tempo of an audio track by a potentiometer. Normally a SerialPort.readline() should be enough to get the right data from the desired Port but in this case I tried to integrate it into XNA. The problem here is that your game can either run with a fixed or a variable timestep. If you are using a variable timestep in XNA the readline method should work for you, if not it will hang because of timing issues. To get around that I used the SerialPort.ReadExisting() method instead. This one is reading the date without any timeout. Different then the readline method you need to seperate your incoming information from binary data such as ‘\n’ (newline) and ‘\r’ (carriage return) on your own. Also sometimes the information you get from this method are incorrect or incomplete. So you need to check that too. I set up a little example which can be downloaded from here.
Tags: arduino, csharp, Curltable, potentiometer, readExisting, readLine, serialPort

