Good people, it turns out that I am communicating an Arduino UNO with a RaspberryPI and what happens to me is that when an Arduino button is pressed it sends a simple serial number to RaspberryPi and when it recives it will emit a sound, the question is that to avoid annoying people pressing the button many times and locking the system, I have put a delay, but apparently this does not work, because if you press the button many times, it is as if the serial was waiting and if you press 5 times the button, every 10 seconds the sound will be emitted as messages continue to arrive from the serial, until the 5 times you have pressed the button, it is as if that were in a waiting queue when using the sleep (). The question is, how can I modify my code so that it receives 1 message from the serial, every 10s and the other pulsations discard them if they are within those 10s.
Code:
ser = serial.Serial('/dev/ttyACM0',9600)
s = [0]
try:
while True:
read_serial=ser.readline()
print read_serial
playSong()
sleep(10)