Exemple #1
0
def dac_sin(time, frequency):
    time = np.arange(0, time, 1 / frequency)
    y = 255 * np.sin(time)
    amplitude = [int(x) for x in y]
    plt.plot(time, amplitude)
    plt.title('Синус')
    plt.xlabel('Время')
    plt.ylabel('Амплитуда sin(time)')
    plt.show()
    for value in amplitude:
        num2dac(value, slee_time = 1 / frequency)
Exemple #2
0
def guess(last_i):
    if not GPIO.input(sc1.comp):
        for i in range(last_i, -1, -1):
            sc1.num2dac(i)
            time.sleep(sc1.time_sleep)
            if GPIO.input(sc1.comp) == 1:
                print(
                    f'Digital value: {i}, ',
                    'Analog value :{0:.{1}f} V'.format(i * sc1.voltage_step,
                                                       sc1.rounded))
                return i
    for i in range(last_i, 2**sc1.bin_depth):
        sc1.num2dac(i)
        time.sleep(sc1.time_sleep)
        if GPIO.input(sc1.comp) == 0:
            print(
                f'Digital value: {i}, ',
                'Analog value :{0:.{1}f} V'.format(i * sc1.voltage_step,
                                                   sc1.rounded))
            return i
Exemple #3
0
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")
Exemple #4
0
import script1 as scr1
import RPi.GPIO as GPIO
import time


try:
    repetitionsNumber = int(input("Print number of repetitions "))
    if repetitionsNumber <= 0:
        raise Exception
    for _ in range(repetitionsNumber):
        for i in range(2 ** scr1.bin_depth):
            scr1.all_out()
            scr1.num2dac(i)
            time.sleep(scr1.time_to_sleep)
        for i in range(2 ** scr1.bin_depth, -1, -1):
            scr1.all_out()
            scr1.num2dac(i)
            time.sleep(scr1.time_to_sleep)
except TypeError:
    print("Number of repetitions must be an integer")
except Exception:
    print("Something went wrong...")
finally:
    scr1.all_out()
    print("Quit")
Exemple #5
0
    GPIO.output(pins, mass)
    time.sleep(1)

lightNumber(value)


import numpy as np
import script1 as sc1

print ("Введите число повторений")

repetitionsNumber = int(input())

for i in range(repetitionsNumber):
    for j in range(256):
        sc1.num2dac(j)
        sc1.lightNumber(j)

    for j in range(255):
        sc1.num2dac(255 - j)
        sc1.lightNumber(255-j)
        
        import numpy as np
import matplotlib.pyplot as plt

print("Введите 3 числа (time, frequency, samplingFrequency)")

time = int(input())
frequency = int(input())
samplingFrequency = int(input())
Exemple #6
0
def repeat(repetitionsNumber):
    for y in range(repetitionsNumber):
        for x in range(256):
            num2dac(x, slee_time=0.01)
        for x in range(255, 0, -1):
            num2dac(x, slee_time=0.01)
Exemple #7
0
try:
    x = np.linspace(0, timee, num=SF)
    y = 127 * (np.sin(2 * np.pi * frequency * x)) + 127
    fig = plt.subplots()

    y_new = np.round(y, 0)
    y_final = y_new.astype(np.int32)

    print(x)
    print(y_final)

    timeout = time.time() + timee

    while True:
        if time.time() > timeout:
            break

        for i in y_final:

            y_final_new = sc1.num2dac(i)
            time.sleep(1 / SF)
            GPIO.output(4, 0)
            GPIO.output(4, 1)

    plt.plot(x, y_final)
    plt.show()

finally:
    DarkALL()
    GPIO.cleanup()
Exemple #8
0
repNum = (int(input('Введите число повторений: ')))
i = 0


def DarkALL():
    for i in range(8):
        GPIO.output(N[i], 0)


DarkALL()

try:
    for j in range(repNum):

        while i <= 255:
            binary = sc1.num2dac(i)
            time.sleep(0.001)
            i += 1
            GPIO.output(4, 0)

            GPIO.output(4, 1)

        while i > 0:
            binary = sc1.num2dac(i)
            time.sleep(0.001)
            i -= 1
            GPIO.output(4, 0)
            GPIO.output(4, 1)

finally:
    DarkALL()
Exemple #9
0
tim = int(input("Введите время в миллисекундах: "))

mas = np.zeros(tim)

for i in range(tim):
    someTime = i / samPe / 1000

    nCol = math.ceil(someTime)

    samplingPerion = nCol * samPe * 1000

    pp = math.sin((samplingPerion - 1) * pi2 / Pe / 1000)

    value = math.ceil((pp + 1) * 128) - 1
    mas[i] = value
    a = num2dac(value)
    lightMas(a)

    print(someTime, nCol, pp, value)

    time.sleep(1 / 1000)

tt = np.arange(0, tim, 1)
plt.plot(tt, mas)
c
plt.show()
time.sleep(1)
plt.close()

GPIO.output(leds, 0)
GPIO.cleanup()