I read continuous serial data from sensor. I splitted it and assigned to 5 variables - a,b,c,d,e. I am trying to calculate the average of each variable for every 5s. Since my sensor is 50Hz, I made the range 250. My implementation is as below. So, the question is - is there any way better to do it, especially on setting the time to be exactly 5 seconds instead of presuming it equal to 250 times of loop?
a,b,c,d,e = [[] for i in range(5)]
for i in range(250):
data = ser.readline().decode() #read from sensor
msg = float(data.split(','))
a.append(msg[0])
b.append(msg[1])
c.append(msg[2])
d.append(msg[3])
e.append(msg[4])
average_a = sum(a)/len(a)
average_b = sum(b)/len(b)
average_c = sum(c)/len(c)
average_d = sum(d)/len(d)
average_e = sum(e)/len(e)