       buf[bufSize] = payload.read();
       if(buf[bufSize] == '\r' || buf[bufSize] == '\n' || bufSize >= buffersize){
         if(buf[bufSize] == '\r' && payload.peek() == '\n') payload.read();
+        
+        //---------REPEAT---------     
+        int repeatBufferSize = 0;
+        int repeats = 0;
+        unsigned long payloadPosition = payload.position();
+        
+        for(int i=0;i<12;i++){
+          if(payload.available()){
+            repeatBuffer[repeatBufferSize] = payload.read();
+            repeatBufferSize++;
+          }else break;
+        }
+
+        if(repeatBufferSize > 6){
+          if(equals(repeatBuffer, 0, 6, "REPEAT", 6)){
+            repeats = getInt(repeatBuffer, 6);
+          }
+        }
+
+        for(int i=0;i<repeats;i++) runLine();
+        
+        payload.seek(payloadPosition);
+        //------------------------
+        
         runLine();
-        strncpy(last, buf, bufSize);
-        lastSize = bufSize;
         bufSize = 0;
       }
       else bufSize++;
     }
     if(bufSize > 0){
       runLine();
-      strncpy(last, buf, bufSize);
-      lastSize = bufSize;
       bufSize = 0;
     }
     payload.close();

/*
Copyright (c) 2017 Seytonic, Spacehuhn (Licensed under MIT)
For more information see: github.com/seytonic/malduino
*/

#include <SPI.h>
#include <SD.h>
#include "Keyboard.h"

//#define debug true // <-- uncomment to turn serial output on
#define CSpin 4 //Chip-Select of the SD-Card reader
#define ledPin 3
#define blinkInterval 50

  return -1;
}

bool equals(char* strA, int start, int end, char* strB, int strLen){
  if(end-start != strLen) return false;
  for(int i=0;i<strLen;i++){
    if(strA[start+i] != strB[i]) return false;
  }
  return true;
}

bool equalsBuffer(int start, int end, char* str){ return equals(buf, start, end, str, String(str).length()); }

int getInt(char* str, int pos){
  String amount = String(str).substring(pos+1,pos+6);
  return amount.toInt();
}

