Advertisement
alphauser420

Oscilloscope 2

Oct 15th, 2023
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import time
  2. import matplotlib.pyplot as plt
  3.  
  4. #import numpy
  5. from drawnow import *
  6.  
  7. # Import the ADS1x15 module.
  8. import Adafruit_ADS1x15
  9.  
  10. # Create an ADS1115 ADC (16-bit) instance.
  11.  
  12. adc = Adafruit_ADS1x15.ADS1115()
  13.  
  14. GAIN = 1
  15.  
  16. val = [ ]
  17.  
  18. cnt = 0
  19.  
  20. plt.ion()
  21.  
  22. # Start continuous ADC conversions on channel 0 using the previous gain value.
  23.  
  24. adc.start_adc(0, gain=GAIN)
  25.  
  26. print('Reading ADS1x15 channel 0')
  27.  
  28. #create the figure function
  29.  
  30. def makeFig():
  31.  
  32. plt.ylim(25,175)
  33.  
  34. plt.title('Practical 3 Osciloscope By [ 6403 , 6409 , 6415 ]')
  35.  
  36. plt.grid(True)
  37.  
  38. plt.ylabel('outputs')
  39.  
  40. plt.plot(val, 'mo-', label='Channel 0')
  41.  
  42. plt.legend(loc='lower right')
  43.  
  44. value = 50
  45. while (True):
  46.  
  47. # Read the last ADC conversion value and print it out.
  48.  
  49. #value = adc.get_last_result()
  50.  
  51.  
  52. if(value > 0 or value == 50 ):
  53. value += 50
  54. if(value >= 190):
  55. for i in range (2) :
  56. value-=50
  57.  
  58.  
  59.  
  60. print('Channel 0: {0}'.format(value))
  61.  
  62. # Sleep for half a second.
  63.  
  64. time.sleep(0.5)
  65.  
  66. val.append(int(value))
  67.  
  68. drawnow(makeFig)
  69.  
  70. plt.pause(.000001)
  71.  
  72. cnt = cnt+1
  73.  
  74.  
  75. if(cnt>50):
  76. val.pop(0)
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement