Hi, I am working on a project where I have a rotary encoder connected to an Arduino Mega board which in turn is connected to my computer via Python. I am using the rotary encoder to measure the to move a virtual object in in the python code up and down.
The idea here is that the object is moved to a certain position on the screen and then something happens (tone is played). So far I got this to work, however there are some issues. I read the input of the rotary encoder with serial.readline() which has to be stopped once the object is in the correct position and the tone is played and the object position is reset. If I keep turning the rotary encoder however, this causes a problem because once the new 'trial' begins, all the information form the turning during the tone playing is read out of the buffer of the Arduino and moves the object on the screen. This messes things up as the buffer controls the object for a little while and not the actual input of the rotary encoder.
So far I have achieved this by closing the serial port after each trial and opening it again, which works, but introduces a delay of 1+ second as it is the time it takes to re-open the serial port. A delay which is much too long between trials.
I therefore wanted to know if there is an option of maybe turning of the buffer capacity of Arduino or something that can reset the buffer of the Arduino at the start of each trial with a python command in order to get rid of the delay and the buffer issue. Or any other idea how I could handle this issue.
Thanks in advance !