Last active
July 2, 2018 11:57
-
-
Save hsnee/65048c5defb975e8f711cd08fa02bd0f to your computer and use it in GitHub Desktop.
miniligo visualization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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