-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDACsin.py
More file actions
35 lines (33 loc) · 1014 Bytes
/
DACsin.py
File metadata and controls
35 lines (33 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import numpy as np
import time
import RPi.GPIO as GPIO
import matplotlib.pyplot as plt
import script1 as scr1
import sys
pi = 3.14
try:
_time = float(input("Print period of time "))
frequency = float(input("Print frequency "))
samplingFrequency = float(input("Print sampling frequency "))
time_ = np.arange(0, _time, 1 / samplingFrequency)
amplitude = np.sin(2 * pi * frequency * time_)
amplitude = (amplitude + 1) * (255 / 2)
plt.plot(time_, amplitude)
plt.title("SIN")
plt.xlabel("Time")
plt.ylabel("Amplitude sin(2 * pi * {} * time)".format(frequency))
plt.show()
c = int(input("Print 1 if you want to continue, else print -1 "))
if c == -1:
sys.exit()
for i in range(len(amplitude)):
scr1.all_out()
scr1.num2dac(int(amplitude[i]))
time.sleep(1 / samplingFrequency)
except TypeError:
print("You must print numbers")
except Exception:
print("Something went wrong...")
finally:
scr1.all_out()
print("Quit")