tttapa / Control-Surface

Arduino library for creating MIDI controllers and other MIDI devices.
GNU General Public License v3.0
1.27k stars 140 forks source link

Bankable::ManyAddresses::CCAbsoluteEncoder #1007

Closed Alexandr010360 closed 9 months ago

Alexandr010360 commented 9 months ago
  1. Hello Peter P! Please help me solve the problem. How can I set the average level of 0x40 in the Bankable::Many Addresses::CCAbsoluteEncoder class? So that when the Arduino power is turned off and when it is turned on again, the average level is maintained. Otherwise, when the encoder is rotated, it resets all settings to 0.
Bankable::ManyAddresses::CCAbsoluteEncoder<10> enc = {
  bank,    // The bank that controls this element.
  {7, 8},   // Encoder connection pins.
  {
    {
      {07, Channel_1}, // Address of bank 1.
      {07, Channel_2}, // Address of bank 2.
      {07, Channel_3}, // Address of bank 3.
      {07, Channel_10},// Address of bank 4.
      {91, Channel_1}, // Address of bank 5.
      {91, Channel_2}, // Address of bank 6.
      {91, Channel_3}, // Address of bank 7.
      {93, Channel_1}, // Address of bank 8.
      {93, Channel_2}, // Address of bank 9.
      {93, Channel_3}, // Address of bank 10.
    }
  },
};
tttapa commented 9 months ago

Loop over the different banks and call CCAbsoluteEncoder::setValue(value, bank):

template <size_t NumBanks>
void initEncoder(Bankable::ManyAddresses::CCAbsoluteEncoder<NumBanks> &enc, uint16_t val) {
  for (setting_t bank = 0; bank < NumBanks; ++bank)
    enc.setValue(val, bank);
}

void setup() {
  initEncoder(enc, 0x40);
  // ...
}
Alexandr010360 commented 9 months ago

Thank you very much! Everything worked out! Everything is ingeniously simple for you! And the library is just great! For all occasions! I wish you good health and creative success!