data = [[8.0, 10.0, 13.0, 17.0, 13.0, 13.0, 10.0],
[9.0, 9.0, 13.0, 17.0, 16.0, 13.0, 11.0],
[9.0, 10.0, 10.0, 14.0, 14.0, 13.0, 12.0],
[8.0, 10.0, 11.0, 14.0, 14.0, 11.0, 11.0],
[8.0, 12.0, 11.0, 16.0, 14.0, 11.0, 11.0],
[8.0, 13.0, 13.0, 14.0, 16.0, 11.0, 13.0],
[8.0, 10.0, 14.0, 14.0, 14.0, 13.0, 13.0],
[8.0, 12.0, 16.0, 17.0, 17.0, 13.0, 11.0],
[12.0, 10.0, 16.0, 14.0, 17.0, 16.0, 13.0],
[8.0, 10.0, 13.0, 17.0, 15.0, 15.0, 11.0],
[9.0, 10.0, 16.0, 15.0, 14.0, 15.0, 14.0],
[12.0, 12.0, 13.0, 17.0, 15.0, 16.0, 14.0],
[8.0, 13.0, 14.0, 15.0, 14.0, 15.0, 14.0],
[10.0, 13.0, 13.0, 20.0, 15.0, 17.0, 14.0],
[9.0, 11.0, 17.0, 18.0, 17.0, 14.0, 16.0],
[8.0, 13.0, 15.0, 18.0, 17.0, 14.0, 16.0],
[10.0, 13.0, 14.0, 18.0, 15.0, 15.0, 15.0],
[9.0, 13.0, 15.0, 17.0, 15.0, 15.0, 15.0],
[12.0, 13.0, 17.0, 20.0, 18.0, 17.0, 14.0],
[10.0, 11.0, 17.0, 18.0, 15.0, 17.0, 15.0],
[13.0, 13.0, 15.0, 20.0, 18.0, 17.0, 17.0],
[12.0, 14.0, 17.0, 21.0, 15.0, 17.0, 17.0],
[12.0, 14.0, 14.0, 18.0, 19.0, 18.0, 17.0],
[10.0, 16.0, 17.0, 21.0, 19.0, 17.0, 15.0],
[13.0, 13.0, 18.0, 18.0, 21.0, 20.0, 17.0],
[11.0, 13.0, 18.0, 21.0, 20.0, 18.0, 17.0],
[11.0, 17.0, 18.0, 18.0, 18.0, 21.0, 18.0],
[13.0, 13.0, 18.0, 21.0, 21.0, 18.0, 20.0],
[13.0, 14.0, 20.0, 22.0, 21.0, 20.0, 20.0],
[13.0, 14.0, 18.0, 22.0, 21.0, 18.0, 15.0],
[11.0, 14.0, 21.0, 21.0, 19.0, 21.0, 15.0],
[11.0, 17.0, 18.0, 21.0, 21.0, 18.0, 15.0],
[14.0, 15.0, 20.0, 21.0, 22.0, 21.0, 21.0],
[13.0, 17.0, 19.0, 23.0, 23.0, 18.0, 20.0],
[14.0, 14.0, 21.0, 22.0, 19.0, 18.0, 19.0],
[11.0, 17.0, 20.0, 23.0, 21.0, 19.0, 20.0],
[16.0, 17.0, 18.0, 23.0, 22.0, 21.0, 21.0],
[14.0, 17.0, 18.0, 25.0, 22.0, 21.0, 21.0],
[15.0, 20.0, 18.0, 25.0, 23.0, 21.0, 20.0],
[16.0, 20.0, 21.0, 24.0, 23.0, 23.0, 21.0],
[15.0, 16.0, 19.0, 25.0, 22.0, 22.0, 19.0],
[16.0, 15.0, 18.0, 25.0, 23.0, 23.0, 19.0],
[11.0, 18.0, 21.0, 25.0, 25.0, 21.0, 21.0],
[13.0, 15.0, 21.0, 26.0, 24.0, 22.0, 21.0],
[17.0, 15.0, 19.0, 28.0, 25.0, 22.0, 21.0],
[15.0, 17.0, 21.0, 28.0, 25.0, 22.0, 23.0],
[16.0, 21.0, 21.0, 25.0, 24.0, 23.0, 19.0],
[14.0, 18.0, 21.0, 25.0, 25.0, 25.0, 23.0],
[14.0, 18.0, 19.0, 26.0, 28.0, 25.0, 21.0],
[14.0, 21.0, 23.0, 26.0, 26.0, 24.0, 21.0],
[15.0, 19.0, 23.0, 27.0, 24.0, 24.0, 22.0],
[16.0, 20.0, 23.0, 26.0, 24.0, 24.0, 23.0],
[17.0, 21.0, 22.0, 26.0, 29.0, 26.0, 22.0],
[14.0, 20.0, 22.0, 29.0, 28.0, 24.0, 25.0],
[17.0, 18.0, 22.0, 29.0, 26.0, 28.0, 24.0],
[14.0, 18.0, 25.0, 29.0, 26.0, 26.0, 25.0],
[17.0, 18.0, 24.0, 29.0, 26.0, 26.0, 25.0],
[20.0, 21.0, 25.0, 29.0, 27.0, 25.0, 25.0],
[15.0, 21.0, 24.0, 29.0, 28.0, 29.0, 24.0],
[15.0, 21.0, 25.0, 31.0, 27.0, 26.0, 28.0],
[18.0, 21.0, 28.0, 30.0, 29.0, 26.0, 26.0],
[20.0, 21.0, 25.0, 31.0, 29.0, 28.0, 26.0],
[18.0, 21.0, 25.0, 30.0, 27.0, 26.0, 28.0],
[18.0, 23.0, 28.0, 31.0, 31.0, 28.0, 26.0],
[17.0, 21.0, 25.0, 30.0, 30.0, 29.0, 24.0],
[18.0, 19.0, 27.0, 32.0, 29.0, 27.0, 26.0],
[18.0, 21.0, 25.0, 30.0, 31.0, 29.0, 29.0],
[20.0, 23.0, 26.0, 30.0, 30.0, 29.0, 26.0],
[18.0, 22.0, 29.0, 31.0, 31.0, 29.0, 26.0],
[19.0, 22.0, 29.0, 33.0, 30.0, 29.0, 27.0],
[18.0, 23.0, 29.0, 30.0, 31.0, 29.0, 26.0],
[19.0, 22.0, 28.0, 33.0, 30.0, 30.0, 28.0],
[21.0, 22.0, 28.0, 32.0, 32.0, 29.0, 26.0],
[18.0, 22.0, 29.0, 36.0, 33.0, 30.0, 27.0],
[18.0, 23.0, 26.0, 36.0, 30.0, 31.0, 26.0],
[18.0, 25.0, 29.0, 33.0, 33.0, 29.0, 29.0],
[18.0, 25.0, 26.0, 34.0, 33.0, 30.0, 29.0],
[18.0, 24.0, 29.0, 34.0, 30.0, 30.0, 29.0],
[18.0, 24.0, 27.0, 33.0, 33.0, 30.0, 29.0],
[19.0, 24.0, 30.0, 34.0, 32.0, 31.0, 29.0],
[21.0, 25.0, 30.0, 37.0, 33.0, 31.0, 30.0],
[20.0, 24.0, 30.0, 35.0, 36.0, 30.0, 27.0],
[18.0, 25.0, 30.0, 34.0, 34.0, 30.0, 30.0],
[19.0, 28.0, 29.0, 35.0, 33.0, 30.0, 31.0],
[21.0, 26.0, 30.0, 37.0, 34.0, 32.0, 27.0],
[21.0, 25.0, 29.0, 37.0, 34.0, 33.0, 30.0],
[19.0, 28.0, 32.0, 34.0, 33.0, 33.0, 33.0],
[23.0, 24.0, 30.0, 36.0, 34.0, 33.0, 30.0],
[22.0, 25.0, 31.0, 36.0, 37.0, 32.0, 31.0],
[19.0, 24.0, 30.0, 37.0, 36.0, 33.0, 30.0],
[19.0, 25.0, 32.0, 37.0, 37.0, 36.0, 32.0],
[23.0, 25.0, 33.0, 35.0, 34.0, 36.0, 33.0],
[19.0, 26.0, 33.0, 39.0, 35.0, 33.0, 31.0],
[23.0, 26.0, 30.0, 39.0, 37.0, 34.0, 30.0],
[23.0, 29.0, 33.0, 38.0, 35.0, 34.0, 33.0],
[22.0, 28.0, 33.0, 38.0, 37.0, 34.0, 33.0],
[22.0, 27.0, 33.0, 38.0, 37.0, 35.0, 32.0],
[23.0, 29.0, 34.0, 38.0, 39.0, 36.0, 34.0],
[22.0, 26.0, 32.0, 38.0, 35.0, 35.0, 36.0],
[25.0, 27.0, 36.0, 41.0, 38.0, 36.0, 36.0],
[25.0, 27.0, 34.0, 41.0, 37.0, 34.0, 34.0],
[24.0, 30.0, 33.0, 41.0, 39.0, 34.0, 36.0],
[25.0, 27.0, 36.0, 40.0, 38.0, 35.0, 34.0],
[24.0, 27.0, 36.0, 41.0, 38.0, 37.0, 34.0],
[25.0, 31.0, 34.0, 40.0, 40.0, 37.0, 34.0],
[24.0, 29.0, 37.0, 40.0, 41.0, 37.0, 37.0],
[28.0, 30.0, 35.0, 44.0, 40.0, 39.0, 37.0],
[28.0, 32.0, 34.0, 45.0, 40.0, 39.0, 34.0],
[24.0, 32.0, 36.0, 42.0, 40.0, 39.0, 35.0],
[24.0, 30.0, 37.0, 42.0, 42.0, 39.0, 37.0],
[28.0, 31.0, 37.0, 42.0, 42.0, 39.0, 35.0]]


from matplotlib import pyplot as plt

def mapf(x, in_min, in_max, out_min, out_max):
    return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min


def toResistance(v_adc):
    Vc = 5.
    Rl = 10000.
    if v_adc <= 0: v_adc = 0.4
    Vout = mapf(v_adc,0,1023, 0.,Vc)
    Rs = Rl*(Vc-Vout)/Vout
    return Rs

dataToPlot = []
for vals in data:
    vals = [toResistance(val) for val in vals]
    top_val = vals[1]
    btm_val = vals[3]
    newVals = [mapf(val,btm_val,top_val, 0.,10.) for val in vals]
    #newVals = []
    #newVals.append(mapf(vals[2],btm_val,top_val, 0.,10.))
    #newVals.append(mapf(vals[3],btm_val,top_val, 0.,10.))
    #newVals.append(mapf(vals[4],btm_val,top_val, 0.,10.))
    #newVals.append(vals[4]-vals[3])
    #newVals = [val-vals[3] for val in vals]
    #dataToPlot.append(newVals)
    vals = newVals
    slope1 = (vals[2]-vals[1])/500
    slope2 = (vals[3]-vals[2])/500
    slope3 = (vals[4]-vals[3])/1000
    slope4 = (vals[5]-vals[4])/1000
    slope5 = (vals[6]-vals[5])/1000
    dataToPlot.append([slope1,slope2,slope3,slope4,slope5])
    #dataToPlot.append([newVals[1]-newVals[2],newVals[6]-newVals[5]])
    #for num in newVals:
    #    dataToPlot.append(num)

plt.plot(dataToPlot)
plt.legend(["1","2","3","4","5","6","7"])
plt.show()



















