 
 int buttonEvent = 0;
 int doorEvent = 0;
+
+int cyclicBufferPosition = 0;
+int lastSerialEventTime = 0;
+bool eventReceived = false;
 
 inline bool isStable(const int lastEvent){
 	return (millis() - lastEvent) > debounceDelay;

#endif
inline void copyFromBuffer(int cyclicBufferPosition){
	for(int i = 0; i < LENGTH; ++i)
		card[i] = buffer[bufferIndex(cyclicBufferPosition + i + offset)];
}

#ifdef STASZEK_MODE

	return index%(BUFSIZE);
}

//called by Arduino framework when there are available bytes in input buffer
void serialEvent(){
        digitalWrite(8, HIGH);
	while (Serial.available())
        {
                char temp = Serial.read();
                if(cyclicBufferPosition < 10){
		  buffer[cyclicBufferPosition++] = temp;
                }else{
                  Serial.flush();
                }
		
	}
	lastSerialEventTime = millis();
        eventReceived = true;
        digitalWrite(8, LOW);
}

inline void cleanBuffer(){
