Created
September 12, 2023 17:18
-
-
Save IrregularShed/4985ac7ce4f05f4c93ca8822537eee81 to your computer and use it in GitHub Desktop.
CircuitPython PT2258 control
This file contains 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
import time | |
import board | |
from adafruit_bus_device.i2c_device import I2CDevice | |
i2c = board.I2C() # uses board.SCL and board.SDA | |
pt2258 = I2CDevice(i2c, 0x44) | |
# define CHANNEL1_VOLUME_STEP_01 0x90 | |
# define CHANNEL1_VOLUME_STEP_10 0x80 | |
# define CHANNEL2_VOLUME_STEP_01 0x50 | |
# define CHANNEL2_VOLUME_STEP_10 0x40 | |
# define CHANNEL3_VOLUME_STEP_01 0x10 | |
# define CHANNEL3_VOLUME_STEP_10 0x00 | |
# define CHANNEL4_VOLUME_STEP_01 0x30 | |
# define CHANNEL4_VOLUME_STEP_10 0x20 | |
# define CHANNEL5_VOLUME_STEP_01 0x70 | |
# define CHANNEL5_VOLUME_STEP_10 0x60 | |
# define CHANNEL6_VOLUME_STEP_01 0xb0 | |
# define CHANNEL6_VOLUME_STEP_10 0xa0 | |
# define MASTER_VOLUME_1STEP 0xe0 | |
# define MASTER_VOLUME_10STEP 0xd0 | |
# define MUTE 0x08 | |
# define SYSTEM_RESET 0xc0 | |
channelsUnits = (0xE0, 0x90, 0x50, 0x10, 0x30, 0x70, 0xB0) | |
channelsTens = (0xD0, 0x80, 0x40, 0x00, 0x20, 0x60, 0xA0) | |
with pt2258: | |
pt2258.write(bytes([0xC0])) # system reset | |
def setChannelVol(channel, dB): | |
baseUnit = channelsUnits[channel] | |
baseTens = channelsTens[ | |
channel | |
] # need to blend these with the BCD representation of the digit | |
dBUnit = baseUnit | (dB % 10) | |
dBTens = baseTens | (dB // 10) | |
with pt2258: | |
pt2258.write(bytes([dBUnit, dBTens])) | |
setChannelVol(0, 0) | |
setChannelVol(1, 0) | |
setChannelVol(2, 0) | |
setChannelVol(3, 0) | |
setChannelVol(4, 0) | |
setChannelVol(5, 0) | |
setChannelVol(6, 0) | |
attnVal = 0 | |
while True: | |
setChannelVol(1, attnVal) | |
setChannelVol(4, 40 - attnVal) | |
attnVal += 1 | |
attnVal %= 40 | |
print(attnVal) | |
time.sleep(0.02) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment