Binary Conversion Selection of 8 bits first 4 bits are Bass last 4 are Treble

I'm trying to make some code for a speaker remote replacement that has tone control. The device has an I2C volume control IC on it: Attached Image I have it setup so I can click a button and it switches between the 9 modes from 0 - 8 addresses on the IC so I added two more 9/10 dimensional array units to store the 4 bits for bass and 4 bits for treble. I modify these bits with a rotary encoder up and down. I then want to add these two 4 bit values back together and store them back in Address 07 as an 8 bit value again. I'm just not sure how to modify the bits back and forth between 4 and 8 bit values. I hold the chip values in a multidimensional array
// Hold volume control data in multidimensional array.
// CurrentValue,MinValue,MaxValue,Red,Green,Blue.
int mem[][6] = {
// 00 VOL : Volume control for all channel (1dB/step)[00000000]0dB to -79dB[1001111], Default Value: MUTE[1010000].
// Maximum Attenuation: Master Volume: -79dB, Trimmer: -20dB.
// Minimum Attenuation: Master Volume: 0dB, Trimmer: 0dB.
{ 25, 0, 80, 200, 0, 80 }, // VOL
// 01 L-BAL : Balance control for Left channel (1dB/step) [00000]0dB to -30dB[11110], MUTE[11111] Default Value: 0dB[00000]).
{ 0, 0, 31, 0, 255, 255 }, // LBAL
// 02 R-BAL : Balance control for Right channel (1dB/step) [00000]0dB to -30dB[11110], MUTE[11111] Default Value: 0dB[00000]).
{ 0, 0, 31, 0, 0, 255 }, // RBAL
// 03 C TRIM :Volume Center Channel Trimmer Control ([00000]0dB to -20dB[10100] Default Value: -10dB[01010]).
{ 10, 0, 20, 255, 255, 0 }, // CTRIM
// 04 SL TRIM :Volume Surround Left Channel Trimmer Control ([00000]0dB to -20dB[10100] Default Value: -10dB[01010]).
{ 10, 0, 20, 0, 255, 0 }, // LTRIM
// 05 SR TRIM :Volume Surround Right Channel Trimmer Control ([00000]0dB to -20dB[10100] Default Value: -10dB[01010]).
{ 10, 0, 20, 255, 0, 0 }, // RTRIM
// Hold volume control data in multidimensional array.
// CurrentValue,MinValue,MaxValue,Red,Green,Blue.
int mem[][6] = {
// 00 VOL : Volume control for all channel (1dB/step)[00000000]0dB to -79dB[1001111], Default Value: MUTE[1010000].
// Maximum Attenuation: Master Volume: -79dB, Trimmer: -20dB.
// Minimum Attenuation: Master Volume: 0dB, Trimmer: 0dB.
{ 25, 0, 80, 200, 0, 80 }, // VOL
// 01 L-BAL : Balance control for Left channel (1dB/step) [00000]0dB to -30dB[11110], MUTE[11111] Default Value: 0dB[00000]).
{ 0, 0, 31, 0, 255, 255 }, // LBAL
// 02 R-BAL : Balance control for Right channel (1dB/step) [00000]0dB to -30dB[11110], MUTE[11111] Default Value: 0dB[00000]).
{ 0, 0, 31, 0, 0, 255 }, // RBAL
// 03 C TRIM :Volume Center Channel Trimmer Control ([00000]0dB to -20dB[10100] Default Value: -10dB[01010]).
{ 10, 0, 20, 255, 255, 0 }, // CTRIM
// 04 SL TRIM :Volume Surround Left Channel Trimmer Control ([00000]0dB to -20dB[10100] Default Value: -10dB[01010]).
{ 10, 0, 20, 0, 255, 0 }, // LTRIM
// 05 SR TRIM :Volume Surround Right Channel Trimmer Control ([00000]0dB to -20dB[10100] Default Value: -10dB[01010]).
{ 10, 0, 20, 255, 0, 0 }, // RTRIM
No description
31 Replies
NonaSuomy
NonaSuomyOP3y ago
// 06 SW TRIM :Volume Sub Woofer Channel Trimmer Control ([00000]0dB to -20dB[10100] Default Value: -10dB[01010]).
{ 10, 0, 20, 255, 0, 255 }, // WTRIM
// 07 TONE CONTROL ([11011101]+10dB to -10dB[01010101]).
// TREBLE BASS
// D7 D6 D5 D4 D3 D2 D1 D0
// 1 0 0 0 1 0 0 0 {10001000}
{ 136, 0, 255, 255, 255, 255 }, // TONE
// 08 MUTE CONTROL (0=OFF 1=MUTE).
{ 1, 0, 1, 50, 0, 0 }, // MUTE
// 09 TONE BASS CONTROL
{ 0, 0, 15, 255, 255, 255 }, // TONE BASS
// 10 TONE TREBLE CONTROL
{ 0, 0, 15, 255, 200, 255 },// TONE TREBLE X 16
// 11 POWER CONTROL (1=OFF 0=ON).
{ 0, 0, 1, 0, 0, 0 }, // POWER
// 12 MATRIX CONTROL (0=OFF 1=ON).
{ 0, 0, 1, 0, 0, 255 } // MATRIX
};
// 06 SW TRIM :Volume Sub Woofer Channel Trimmer Control ([00000]0dB to -20dB[10100] Default Value: -10dB[01010]).
{ 10, 0, 20, 255, 0, 255 }, // WTRIM
// 07 TONE CONTROL ([11011101]+10dB to -10dB[01010101]).
// TREBLE BASS
// D7 D6 D5 D4 D3 D2 D1 D0
// 1 0 0 0 1 0 0 0 {10001000}
{ 136, 0, 255, 255, 255, 255 }, // TONE
// 08 MUTE CONTROL (0=OFF 1=MUTE).
{ 1, 0, 1, 50, 0, 0 }, // MUTE
// 09 TONE BASS CONTROL
{ 0, 0, 15, 255, 255, 255 }, // TONE BASS
// 10 TONE TREBLE CONTROL
{ 0, 0, 15, 255, 200, 255 },// TONE TREBLE X 16
// 11 POWER CONTROL (1=OFF 0=ON).
{ 0, 0, 1, 0, 0, 0 }, // POWER
// 12 MATRIX CONTROL (0=OFF 1=ON).
{ 0, 0, 1, 0, 0, 255 } // MATRIX
};
So once I select the 9 position for BASS and then dial it up and down between 0 -> 15 (4 bits) and then select position 10 for TREBLE and dial it between 0->15 (4 bits) How do I combined those both back into 8 bits to store in 07 position. How would I also separate the 8 into two 4 bit values to store back in position 9 / 10 of the multidirectional array spots?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
Icesythe7 --verbose
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
10001000
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
upperbits = date & ?; Need the upper and lower spit to two 4 bit
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
then how do you put them back together if you changed them separately? Say you added the decimal 4 to the lower then subtracted decimal 4 from the upper how do you put the lower and upper back together again after the manipulation to 8 bits again?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
ok
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
Thank you I was just trying to manipulate it but failing https://www.onlinegdb.com/fork/oSGxtpL1Av
GDB online Debugger
Online GDB is online ide with compiler and debugger for C/C++. Code, Compiler, Run, Debug Share code nippets.
NonaSuomy
NonaSuomyOP3y ago
Need to store the values as decimals in the multi dimensional array Using a rotary encoder
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
Lower bits = 0x9
Upper bits = 0xA
MultiArrayVal9 = 10
MultiArrayVal10 = A

New value = 0xA9
MultiArrayVal7 = 88
Lower bits = 0x9
Upper bits = 0xA
MultiArrayVal9 = 10
MultiArrayVal10 = A

New value = 0xA9
MultiArrayVal7 = 88
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
yes after manipulating 9 and 10 adding or subtracting 1 to it that comes from rotating the rotary encoder
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
// Check if encoder has changed its position from last time or state select (LED Colour update workaround).
newENC = EncKnob.read();
if (newENC != EncPosition || stateSelectLast != selectState) {
EncPosition = newENC;
Serial.print("ENC = ");
Serial.print(newENC);
Serial.println();
// NJW1150 6 Channel Electronic Volume Control.
// 6-Chnnel Master Volume 0 to –79dB, MUTE.
// Balance control for L, R-ch 0 to –30dB, MUTE.
// Trim Level Control for C, SL, SR, SW-ch 0 to –20dB.
// Independent Tone Control (Bass, Treble) for L, R-ch.
// I2C Control Command.
Serial.print("State: ");
Serial.println(selectState);
// Set LED colour to show which item in the mode select the control is at (Red = Vol, etc).
setColor(mem[selectState][3], mem[selectState][4], mem[selectState][5]);
// Reset encoder to prior value if above max of volume processor.
if (newENC > mem[selectState][2]) {
Serial.print("Reset encoder to highest value allowed ");
Serial.println(mem[selectState][2]);
EncKnob.write(mem[selectState][2]);
}
// Reset encoder to prior value if above min of volume processor.
else if (newENC < mem[selectState][1]) {
Serial.print("Reset encoder to lowest value allowed ");
Serial.println(mem[selectState][1]);
EncKnob.write(mem[selectState][1]);
}
mem[selectState][0] = newENC; // Update mem variable with current encoder value selected.
i2cmd(selectState, newENC); // Send I2C command with updated encoder value to NJW1150.
stateSelectLast = selectState; // Track last select state change.
}
// Check if encoder has changed its position from last time or state select (LED Colour update workaround).
newENC = EncKnob.read();
if (newENC != EncPosition || stateSelectLast != selectState) {
EncPosition = newENC;
Serial.print("ENC = ");
Serial.print(newENC);
Serial.println();
// NJW1150 6 Channel Electronic Volume Control.
// 6-Chnnel Master Volume 0 to –79dB, MUTE.
// Balance control for L, R-ch 0 to –30dB, MUTE.
// Trim Level Control for C, SL, SR, SW-ch 0 to –20dB.
// Independent Tone Control (Bass, Treble) for L, R-ch.
// I2C Control Command.
Serial.print("State: ");
Serial.println(selectState);
// Set LED colour to show which item in the mode select the control is at (Red = Vol, etc).
setColor(mem[selectState][3], mem[selectState][4], mem[selectState][5]);
// Reset encoder to prior value if above max of volume processor.
if (newENC > mem[selectState][2]) {
Serial.print("Reset encoder to highest value allowed ");
Serial.println(mem[selectState][2]);
EncKnob.write(mem[selectState][2]);
}
// Reset encoder to prior value if above min of volume processor.
else if (newENC < mem[selectState][1]) {
Serial.print("Reset encoder to lowest value allowed ");
Serial.println(mem[selectState][1]);
EncKnob.write(mem[selectState][1]);
}
mem[selectState][0] = newENC; // Update mem variable with current encoder value selected.
i2cmd(selectState, newENC); // Send I2C command with updated encoder value to NJW1150.
stateSelectLast = selectState; // Track last select state change.
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
mem[selectState][0] = newENC; selectState == the first dimension of the array to select what option we are controlling and that is selected by pushing the button in the encoder spindle the following 0 is where the encoder value is stored so selectState would be 9 or 10 to store the bass and treble separate and 7 would store them together for the actual I2C command for the chip to alter those on the hardware The button to change states:
buttonStateSelect = digitalRead(selectPin);
// Filter out any noise by setting a time buffer.
if ((millis() - lastDebounceTime) > debounceDelay) {
// If the button has been pressed.
if (buttonStateSelect == HIGH) {
selectState++;
lastDebounceTime = millis(); // Set the current time.
// Reset count if over max mode number.
if (selectState > 10) {
selectState = 0;
}
// Configure encoder with the value from memory before changing control.
EncKnob.write(mem[selectState][0]);
}
buttonStateSelect = digitalRead(selectPin);
// Filter out any noise by setting a time buffer.
if ((millis() - lastDebounceTime) > debounceDelay) {
// If the button has been pressed.
if (buttonStateSelect == HIGH) {
selectState++;
lastDebounceTime = millis(); // Set the current time.
// Reset count if over max mode number.
if (selectState > 10) {
selectState = 0;
}
// Configure encoder with the value from memory before changing control.
EncKnob.write(mem[selectState][0]);
}
The i2c cmd gets sent to speaker like this:
// Send I2C commands to NJW1150.
void i2cmd(int cmd, int val) {
Wire.beginTransmission(0x44); // Send I2C command to NJW1150's default address.
Wire.write(cmd); // Item to control.
Wire.write(val); // Value to set to.
Wire.endTransmission(); // Send data via I2C.
Serial.print("CMD: ");
Serial.print(cmd);
Serial.print(", Value: ");
Serial.println(val);
}
// Send I2C commands to NJW1150.
void i2cmd(int cmd, int val) {
Wire.beginTransmission(0x44); // Send I2C command to NJW1150's default address.
Wire.write(cmd); // Item to control.
Wire.write(val); // Value to set to.
Wire.endTransmission(); // Send data via I2C.
Serial.print("CMD: ");
Serial.print(cmd);
Serial.print(", Value: ");
Serial.println(val);
}
You can see the data in the multiD in my fork of your online compiler code The second dimension is stored like this // CurrentValue,MinValue,MaxValue,Red,Green,Blue.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
GDB online Debugger
Online GDB is online ide with compiler and debugger for C/C++. Code, Compiler, Run, Debug Share code nippets.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
NonaSuomy
NonaSuomyOP3y ago
What is the & doing?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?