Exemple #1
0
import My_GPIO as mgp

max_voltage = 3.3

mgp.StartRun()

while (True):

    print("Enter value (-1 to exit) > ", end="")

    try:
        num = int(input())

    except:
        print("Wrong input!")
        continue

    if (num == -1):
        print("Exit...")
        break

    if (num < 0 or num > 255):
        print("Wrong input!")
        continue

    mgp.num2dac(num)
    print("{num} = {volt}V".format(num=num,
                                   volt=round(max_voltage * num / 255, 2)))
    print(mgp.GetStatus())

mgp.FinishRun()
Exemple #2
0
import My_GPIO as mgp

mgp.StartRun()

max_voltage = 3.3

while (True):

    l = 0
    r = 255

    while (r - l > 1):

        num = (l + r) // 2
        mgp.num2dac(num)

        if (mgp.GetStatus()):
            l = num
            continue

        else:
            r = num

    print("Digital value: {num}, Analog value: {volt} V".format(
        num=r, volt=round(max_voltage * r / 255, 2)))
    # mgp.time.sleep (0.5)

mgp.FinishRun()
Exemple #3
0
import My_GPIO as mgp
from scipy.io import wavfile
import numpy as np

samplerate, data = wavfile.read ("ssound.wav")

sleep = 1 / 44100
sound = np.array (data)
sound = np.int32 (sound[:,0])

mgp.StartRun()

print ("Wait...")

for i_music in range (len (sound)):
    sound[i_music] = (sound[i_music] + 32768) // 256

print ("Playing!")

for i_music in sound:
    mgp.num2dac (i_music)
    mgp.time.sleep (0)
    mgp.time.sleep (0)
    mgp.time.sleep (0)

mgp.FinishRun()

# data1 = [i[0] for i in data]
# data2 = [i[1] for i in data]

# print ( min (data1), max (data1))
Exemple #4
0
def Test2():
    for i_music in voltage:
        mgp.num2dac(i_music)
        mgp.time.sleep(sleep)
        mgp.num2dac(0)
        mgp.time.sleep(sleep)
Exemple #5
0
import My_GPIO as mgp
from scipy.io import wavfile
import wave
import time
import numpy as np

mgp.StartRun()

samplingFrequency = 256
sleep = 1 / samplingFrequency
frequency = 1

time = np.arange(0, 1 / frequency, sleep)
voltage = np.uint8(127 * (np.sin(time * frequency * 2 * np.pi) + 1) + 1)


def Test1():
    for i_music in voltage:
        mgp.num2dac(i_music)
        mgp.time.sleep(sleep)


def Test2():
    for i_music in voltage:
        mgp.num2dac(i_music)
        mgp.time.sleep(sleep)
        mgp.num2dac(0)
        mgp.time.sleep(sleep)


while True:
Exemple #6
0
import My_GPIO as gpio

gpio.StartRun()

gpio.ChangingBright(0)

gpio.FinishRun()
Exemple #7
0
import My_GPIO as mgp

mgp.StartRun()

print("Введите количество повторений: ", end="")
inp = input().split()

try:
    inp = int(inp[0])
except:
    print("Неверный ввод. Пожалуйста, соблюдайте правила ввода.")
    exit()

if (inp < 0):
    print("Неверный ввод. Пожалуйста, соблюдайте правила ввода.")
    exit()

for i_iter in range(inp):

    for i_light in range(256):
        mgp.num2dac(i_light)
        mgp.time.sleep(0.005)
        # print (i_light)

    for i_light in range(255, -1, -1):
        mgp.num2dac(i_light)
        mgp.time.sleep(0.005)
        # print (i_light)

mgp.FinishRun()
Exemple #8
0
samplingFrequency = 100
sleep = 1 / samplingFrequency
frequency = 0.5

time    = np.arange (0, 1 / frequency, sleep)
voltage = np.uint8 (127 * (np.sin (time * frequency * 2 * np.pi) + 1) + 1)

fig = plt.figure (figsize = (7, 7))
ax  = fig.add_subplot (1,1,1)

ax.plot (time, voltage, linewidth = 3, alpha = 0.5, label = "$U (t)$", color = "blue")
ax.scatter (time, voltage, s = 40, marker = "_", color = "red")

ax.set_title ("График $U (t)$", fontsize = 20)
ax.set_ylabel ('$U$, ед', fontsize = 20)
ax.set_xlabel ('$t$, с',  fontsize = 20)

ax.grid (True)
ax.legend()
plt.savefig ("time-sin.pdf")

mgp.StartRun()

for i_repeat in range (10):
    for i_time in range (len (time)):
        mgp.num2dac (voltage[i_time])
        mgp.time.sleep (sleep)
        # print (voltage[i_time])

mgp.FinishRun()