Open huggre opened 3 years ago
Please always try to post a minimal example, with as little unrelated code as possible, and post links to the external libraries you're using.
The compiler complains because there is no declaration of any variable lcd
inside of the MySelectorCallback
class. A global variable lcd
is declared further down the line, but you cannot use it before its declaration. You could move that declaration before the MySelectorCallback
, but writing to global variables like that is often a bad idea. Instead, you could pass a reference to the LCD display to your callback:
#include <Encoder.h>
#include <Control_Surface.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Custom callback to handle output for a selector.
class MySelectorCallback {
public:
// Constructor
MySelectorCallback(LiquidCrystal_I2C &lcd, uint8_t col, uint8_t row)
: lcd(lcd), col(col), row(row) {}
// Begin function is called once by Control Surface.
// Use it to initialize everything.
void begin() {}
// Update function is called continuously by Control Surface.
// Use it to implement things like fading, blinking ...
void update() {}
// Update function with arguments is called when the setting
// changes.
// Use it to update the text on the LCD.
void update(setting_t oldSetting, setting_t newSetting) {
(void) oldSetting; // unused in this example
lcd.setCursor(col, row);
lcd.print(newSetting);
}
private:
LiquidCrystal_I2C &lcd;
uint8_t col, row;
};
USBMIDI_Interface usbmidi;
LiquidCrystal_I2C lcd(0x27, 20, 4);
Bank<3> bank = {16};
GenericEncoderSelector<3, MySelectorCallback> selector = {
bank, // bank to manage
{lcd, 1, 0}, // selector callback
{11, 12}, // encoder pins
4, // encoder pulses per step
Wrap::Clamp, // clamp or wrap around when going beyond maximum/minimum setting
};
void setup() {
// Setup LCD
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("hello everyone");
lcd.setCursor(1,1);
lcd.print("konichiwaa");
Control_Surface.begin();
}
void loop() {
Control_Surface.loop();
}
Perfect!!, I will make sure to clean up my code next time.
By the way, have not had any latency issues over USB with the Teensy 2.0 so far.
By the way, have not had any latency issues over USB with the Teensy 2.0 so far.
Thanks for letting me know, I'll add it to the readme for the next release!
Hi, I was hoping someone could show me how to declare a 1602 Liquid Crystal LCD within a custom selector callback. The callback is working correctly when printing the selected bank ID to the serial monitor, however I need to print the selected bank ID to the LCD. Whenever I try to print to the LCD I get a "'lcd' was not declared in this scope" error. Here is my code: