|  | @@ -9,7 +9,8 @@ import serial
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  #initialize serial port
 | 
	
		
			
				|  |  |  ser = serial.Serial()
 | 
	
		
			
				|  |  | -ser.port = '/dev/ttyS3' #Arduino serial port
 | 
	
		
			
				|  |  | +ser.port = "COM3"
 | 
	
		
			
				|  |  | +# ser.port = '/dev/ttyS2' #Arduino serial port
 | 
	
		
			
				|  |  |  ser.baudrate = 115200
 | 
	
		
			
				|  |  |  ser.timeout = 10 #specify timeout when using readline()
 | 
	
		
			
				|  |  |  ser.open()
 | 
	
	
		
			
				|  | @@ -20,25 +21,38 @@ if ser.is_open==True:
 | 
	
		
			
				|  |  |  # Create figure for plotting
 | 
	
		
			
				|  |  |  fig = plt.figure()
 | 
	
		
			
				|  |  |  ax = fig.add_subplot(1, 1, 1)
 | 
	
		
			
				|  |  | -xs = [] #store trials here (n)
 | 
	
		
			
				|  |  | -ys = [] #store relative frequency here
 | 
	
		
			
				|  |  | -rs = [] #for theoretical probability
 | 
	
		
			
				|  |  | +xs = [] # time 
 | 
	
		
			
				|  |  | +ys = [] # shoult temp
 | 
	
		
			
				|  |  | +rs = [] # is temp
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # This function is called periodically from FuncAnimation
 | 
	
		
			
				|  |  | +last_i = 1
 | 
	
		
			
				|  |  |  def animate(i, xs, ys):
 | 
	
		
			
				|  |  | +    global last_i
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      #Aquire and parse data from serial port
 | 
	
		
			
				|  |  | -    line=ser.readline()      #ascii
 | 
	
		
			
				|  |  | +    line=ser.readline()     #ascii
 | 
	
		
			
				|  |  | +    try:
 | 
	
		
			
				|  |  | +        line.decode()
 | 
	
		
			
				|  |  | +    except:
 | 
	
		
			
				|  |  | +        return
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      line_as_list = line.split(b',')
 | 
	
		
			
				|  |  | -    i = int(line_as_list[0])
 | 
	
		
			
				|  |  | -    relProb = line_as_list[1]
 | 
	
		
			
				|  |  | -    relProb_as_list = relProb.split(b'\n')
 | 
	
		
			
				|  |  | -    relProb_float = float(relProb_as_list[0])
 | 
	
		
			
				|  |  | +    i = int(line_as_list[0].strip())
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if (i-last_i) < 1000:
 | 
	
		
			
				|  |  | +        return
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +    print(line.decode().strip())
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    last_i = i
 | 
	
		
			
				|  |  | +    should_float = float(line_as_list[1].strip())
 | 
	
		
			
				|  |  | +    is_float = float(line_as_list[2].strip())
 | 
	
		
			
				|  |  |  	
 | 
	
		
			
				|  |  |  	# Add x and y to lists
 | 
	
		
			
				|  |  |      xs.append(i)
 | 
	
		
			
				|  |  | -    ys.append(relProb_float)
 | 
	
		
			
				|  |  | -    rs.append(0.5)
 | 
	
		
			
				|  |  | +    ys.append(should_float)
 | 
	
		
			
				|  |  | +    rs.append(is_float)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      # Limit x and y lists to 20 items
 | 
	
		
			
				|  |  |      #xs = xs[-20:]
 | 
	
	
		
			
				|  | @@ -55,9 +69,9 @@ def animate(i, xs, ys):
 | 
	
		
			
				|  |  |      plt.title('This is how I roll...')
 | 
	
		
			
				|  |  |      plt.ylabel('Relative frequency')
 | 
	
		
			
				|  |  |      plt.legend()
 | 
	
		
			
				|  |  | -    plt.axis([1, None, 0, 1.1]) #Use for arbitrary number of trials
 | 
	
		
			
				|  |  | +    plt.axis([None, None, 0, 120]) #Use for arbitrary number of trials
 | 
	
		
			
				|  |  |      #plt.axis([1, 100, 0, 1.1]) #Use for 100 trial demo
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  # Set up plot to call animate() function periodically
 | 
	
		
			
				|  |  | -ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys), interval=1000)
 | 
	
		
			
				|  |  | +ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys))
 | 
	
		
			
				|  |  |  plt.show()
 |