Skip to content

Instantly share code, notes, and snippets.

@hsnee
Last active July 2, 2018 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsnee/65048c5defb975e8f711cd08fa02bd0f to your computer and use it in GitHub Desktop.
Save hsnee/65048c5defb975e8f711cd08fa02bd0f to your computer and use it in GitHub Desktop.
miniligo visualization
import RPi.GPIO as GPIO
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid')
import time
import numpy as np
i, full_wavelength = 0, 0
lst, luxes = [], []
plt.figure()
plt.ion()
while True:
# check for trigger
input_state = GPIO.input(18) # state of button
if input_state == False: # i.e. the button is pressed
x, y = inject()
lsti = []
lstj = []
for i,j in zip(x,y):
lsti.append(i)
lstj.append(j)
plt.plot(lsti,lstj)
time.sleep(0.1) # pause for this amount of time between plotting each 2 consecutive points.
# if button is not pressed, calculate calibrated signal:
strain = calibrate(lux,full_wavelength)
# keep the number of plotted points at a max of 50 to enhance performance:
if len(lst)>50:
del lst[0]
# finally, plot calibrated signal:
lst.append(strain)
plt.plot(i, lst)
i+=0.1
plt.show()
plt.pause(0.01)
plt.xlim((i-10,i+10)) # keep plot centered around most recent data point
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment