Created
November 13, 2023 23:41
-
-
Save jedgarpark/b6a61e46a5d44cadcf9d8e9e9efcccd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries | |
# SPDX-License-Identifier: MIT | |
"""Simple demo of writing a sine wave to the AD569x DAC.""" | |
import math | |
import board | |
import busio | |
from adafruit_seesaw import seesaw, rotaryio, digitalio | |
import adafruit_ad569x | |
i2c = busio.I2C(board.SCL1, board.SDA1, frequency=400_000) | |
# Initialize AD569x | |
dac = adafruit_ad569x.Adafruit_AD569x(i2c) | |
# length of the sine wave | |
LENGTH = 1000 | |
# sine wave values written to the DAC | |
sin_value = [ | |
int(math.sin(math.pi * 2 * i / LENGTH) * ((2**15) - 1) + 2**15) | |
for i in range(LENGTH) | |
] | |
tri_value = [ | |
int((2 * math.acos(math.sin(math.pi * 2 * i / LENGTH))) / math.pi * ((2**15) - 1)) | |
for i in range(LENGTH) | |
] | |
saw_value = [ | |
int((i / LENGTH) * ((2**15) - 1)) | |
for i in range(LENGTH) | |
] | |
seesaw = seesaw.Seesaw(i2c, 0x36) | |
seesaw.pin_mode(24, seesaw.INPUT_PULLUP) | |
button = digitalio.DigitalIO(seesaw, 24) | |
button_held = False | |
encoder = rotaryio.IncrementalEncoder(seesaw) | |
last_position = None | |
print("AD5693 16-bit DAC") | |
while True: | |
for v in saw_value: | |
dac.value = v | |
position = -encoder.position | |
if position != last_position: | |
last_position = position | |
print("Position: {}".format(position)) | |
if not button.value and not button_held: | |
button_held = True | |
print("Button pressed") | |
if button.value and button_held: | |
button_held = False | |
print("Button released") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment