var accBuffer0[4] = 0,0,0,0    # here we save the last 4 values of acc[0]
var accBufferPos0 = 0        # here we store where the oldest value is
var accBuffer1[4] = 0,0,0,0
var accBufferPos1 = 0
var sumacc0
var sumacc1

onevent acc
  accBuffer0[accBufferPos0] = acc[0]-2    #we read the accelerometer value. We subtract 2 because the accelerometer is not flat.
  accBufferPos0 = (accBufferPos0 + 1) % 4  #we update the information where the latest value is
  sumacc0 = accBuffer0[0] + accBuffer0[1] + accBuffer0[2] + accBuffer0[3] #we sum the whole
  accBuffer1[accBufferPos1] = acc[1]
  accBufferPos1 = (accBufferPos1 + 1) % 4
  sumacc1 = accBuffer1[0] + accBuffer1[1] + accBuffer1[2] + accBuffer1[3]

  motor.left.target=130-sumacc0*15-sumacc1*15
  motor.right.target=130+sumacc0*15-sumacc1*15