tttapa / Control-Surface

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

Don't get Bankable::CCRotaryEncoder to work, error does not name type #253

Open bobtorxx opened 4 years ago

bobtorxx commented 4 years ago

Hallo Pieter,

First of all, this library and the work you put in to it is incredible! Its super awesome and its works fabulous! Through your examples and documentation I learned a lot about coding in Arduino. I had very little experience in coding en through this project of creating a midi controller I learned a lot so also thanks for that. At the moment I'm working on a controller. The idea is to have a bankable rotary encoder with a increment switch which scrolls through 3 banks. The 3 banks are connected with 3 leds (RGB) so that all the settings together get a colour.

I made it work with a potentiometer and a switch. However no matter what I try with example of the Encoder I don't seem to get it work. I get the error:

exit status 1 'CCRotaryEncoder' in namespace 'CS::Bankable' does not name a type"

What am I doing wrong or is it not possible?

I hope this is the right place to ask for such a question, it is the first time I post something on GitHub so excuse me if its the wrong formatting or place.

Thanks again! and greetings from Gijs


#include <Control_Surface.h> // Include the Control Surface library

// Instantiate a MIDI over serial interface.
auto &serial = Serial;
SerialMIDI_Interface<decltype(serial)> midi = {serial, MIDI_BAUD};

const pin_t redPin = 5;
const pin_t greenPin = 6;
const pin_t bluePin = 7;

Bank<3> bank;
// Selector to change banks
IncrementSelector<3> selector = {
  bank,       // Bank to manage
  2,          // push button pin
};

/*
  // Instantiate a CCPotentiometer object
  Bankable::CCPotentiometer potentiometer = {
  {bank, BankType::CHANGE_ADDRESS},     // Bank configuration
  A0,                                   // Analog pin connected to potentiometer
  {0x01}, // midi cc adress
  };
*/

Bankable::CCRotaryEncoder enc = {
  {bank, BankType::CHANGE_ADDRESS},     // Bank configuration
  {2, 3}, //pins of encoder
  {0x01}, // midi cc adress
  1,     //multiplier
  4,     //4pulses per step
};

using namespace MIDI_Notes;

CCRangeLEDsPWM<3> RGB = { .      // RGB LED
  { redPin, greenPin, bluePin }, // LED pin list
  0x01,                          // start address of range
};

void setup() {
  Control_Surface.begin(); // Initialize Control Surface
  Serial.begin(115200);
}

void loop() {
  Control_Surface.loop(); // Update the Control Surface
}
tttapa commented 4 years ago

You have to include the Encoder library first, please see the documentation and this example:

#include <Encoder.h> // Include the Encoder library.
// This must be done before the Control Surface library.
#include <Control_Surface.h> // Include the Control Surface library

There's also a stray period on this line:

CCRangeLEDsPWM<3> RGB = { .      // RGB LED
                          ^~~~

In your setup, you're calling both Control_Surface.begin() and Serial.begin(115200) . Control Surface will initialize your MIDI interface using Serial to MIDI_BAUD, because that's what you specified on line 5, but then you override this by initializing the Serial port to a different baud rate yourself. It's best to specify the correct baud rate once on line 5, and get rid of the Serial.begin in the setup.

bobtorxx commented 4 years ago

Thanks for your fast response. Got it working :) So stupid of me I should knew that but I guess I have been staring at the screen for to long to see it. Now I got it working I see that wen I turn the encoder it doesn't increment. It jumps from a value of 1 and then immediate to 127. Instead of incrementing in steps (like the example with te potmeter). Thanks again

tttapa commented 4 years ago

Yes, that's the intended behavior. CCRotaryEncoder sends relative messages. 127 represents a value of -1 in two's complement. You have to select a relative mode in your DAW, or use CCAbsoluteEncoder.

luca-art commented 4 years ago

By the way, and hello, can CCAbsoluteEncoder be used within a bank? I did not see it in bankable list. And with a multiplexer CD74HC4067? Thank you

tttapa commented 4 years ago

At the moment, this is not possible with the master version, but you can use the share-encoder branch: https://tttapa.github.io/Control-Surface-doc/share-encoder/Doxygen/d7/d2c/classBankable_1_1CCAbsoluteEncoder.html

You cannot use rotary encoders with multiplexers.

luca-art commented 4 years ago

Ok thanks