Микроконтроллер ESP32 имеет два 8-битных канала ЦАП (цифро-аналоговый преобразователь), подключенных к GPIO25 (канал 1) и GPIO26 (канал 2).
from machine import Pin, DAC from time import sleep_us #define AnalogOut 25 dac0=DAC(Pin(25)) while (True): for DACValue_0 in range(255): print(DACValue_0) dac0.write(DACValue_0) sleep_us(1)
from math import sin, pi from machine import DAC from machine import Pin dac0 = DAC(Pin(25)) Chapter 7 • Analogue-Signal Generation ● 79 dac1 = DAC(Pin(26)) offset = 128 amplitude = 127 bufferlength = 100 # create a buffer containing a sine-wave buf = bytearray(100) for n in range(len(buf)): buf[n] = offset + int(amplitude * sin(2*pi*n/len(buf))) while 1: for i in range(len(buf)): dac0.write(buf[i]) if buf[i] > amplitude: dac1.write(255) else: dac1.write(0)