diff --git a/README.md b/README.md index 885845b3..ccde5f4e 100644 --- a/README.md +++ b/README.md @@ -283,6 +283,10 @@ https://github.com/neu-rah/AnsiStream - Unix terminal +**Grove RGB LCD I2C 2x16** + +https://wiki.seeedstudio.com/Grove-LCD_RGB_Backlight/ + **Web browser** - ESP8266 (builtin) diff --git a/examples/GroveRGB/GroveRGB/GroveRGB.ino b/examples/GroveRGB/GroveRGB/GroveRGB.ino new file mode 100644 index 00000000..33a57a67 --- /dev/null +++ b/examples/GroveRGB/GroveRGB/GroveRGB.ino @@ -0,0 +1,207 @@ +#include + +/******************** +Sept. 2014 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com +Nov. 2020 Graham Whaley - adapted to Grove RGB LCD + +menu output to Grove RGB LCD I2C +output: GROVERGBLCD : https://wiki.seeedstudio.com/Grove-LCD_RGB_Backlight/ +input: click encoder and Serial +board: PJRC Teensy 4.0 : https://www.pjrc.com/store/teensy40.html +***/ + +#include +#include +#include +#include +#include +#include +#include + +using namespace Menu; + +// LCD, standard Grove I2C devices ///////////// +rgb_lcd lcd; + +// Encoder ///////////////////////////////////// +#define encA 3 +#define encB 2 +//this encoder has a button here +#define encBtn 4 + +ClickEncoder clickEncoder(encA,encB,encBtn,2); +ClickEncoderStream encStream(clickEncoder,1); + +//input from the clickencoder + serial +serialIn serial(Serial); +menuIn* inputsList[]={&encStream,&serial}; +chainStream<2> in(inputsList);//3 is the number of inputs + +#define LEDPIN LED_BUILTIN //Teensy 4.0 LED pin + +result doAlert(eventMask e, prompt &item); + +result showEvent(eventMask e,navNode& nav,prompt& item) { + Serial.print("event: "); + Serial.println(e); + return proceed; +} + +int test=55; + +result action1(eventMask e,navNode& nav, prompt &item) { + Serial.print("action1 event: "); + Serial.print(e); + Serial.println(", proceed menu"); + Serial.flush(); + return proceed; +} + +result action2(eventMask e,navNode& nav, prompt &item) { + Serial.print("action2 event: "); + Serial.print(e); + Serial.print(", quiting menu."); + Serial.flush(); + return quit; +} + +int ledCtrl=LOW; + +result myLedOn() { + ledCtrl=HIGH; + return proceed; +} +result myLedOff() { + ledCtrl=LOW; + return proceed; +} + +TOGGLE(ledCtrl,setLed,"Led: ",doNothing,noEvent,noStyle//,doExit,enterEvent,noStyle + ,VALUE("On",HIGH,doNothing,noEvent) + ,VALUE("Off",LOW,doNothing,noEvent) +); + +int selTest=0; +SELECT(selTest,selMenu,"Select",doNothing,noEvent,noStyle + ,VALUE("Zero",0,doNothing,noEvent) + ,VALUE("One",1,doNothing,noEvent) + ,VALUE("Two",2,doNothing,noEvent) +); + +int chooseTest=-1; +CHOOSE(chooseTest,chooseMenu,"Choose",doNothing,noEvent,noStyle + ,VALUE("First",1,doNothing,noEvent) + ,VALUE("Second",2,doNothing,noEvent) + ,VALUE("Third",3,doNothing,noEvent) + ,VALUE("Last",-1,doNothing,noEvent) +); + +//customizing a prompt look! +//by extending the prompt class +class altPrompt:public prompt { +public: + altPrompt(constMEM promptShadow& p):prompt(p) {} + Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t) override { + return out.printRaw(F("special prompt!"),len);; + } +}; + +MENU(subMenu,"Sub-Menu",showEvent,anyEvent,noStyle + ,OP("Sub1",showEvent,anyEvent) + ,OP("Sub2",showEvent,anyEvent) + ,OP("Sub3",showEvent,anyEvent) + ,altOP(altPrompt,"",showEvent,anyEvent) + ,EXIT(" + #include + + namespace Menu { + + class grovergblcdOut:public cursorOut { + public: + rgb_lcd* device; + inline grovergblcdOut(rgb_lcd* o,idx_t *t,panelsList &p,menuOut::styles s=menuOut::minimalRedraw) + :cursorOut(t,p,s),device(o) {} + size_t write(uint8_t ch) override {return device->write(ch);} + void clear() override { + device->clear(); + panels.reset(); + } + void setCursor(idx_t x,idx_t y,idx_t panelNr=0) override { + const panel p=panels[panelNr]; + device->setCursor(p.x+x,p.y+y); + } + idx_t startCursor(navRoot& root,idx_t x,idx_t y,bool charEdit,idx_t panelNr=0) override {return 0;} + idx_t endCursor(navRoot& root,idx_t x,idx_t y,bool charEdit,idx_t panelNr=0) override {return 0;} + idx_t editCursor(navRoot& root,idx_t x,idx_t y,bool editing,bool charEdit,idx_t panelNr=0) override { + trace(MENU_DEBUG_OUT<<"lcdOut::editCursor "<noBlink(); + device->noCursor(); + if (editing) { + device->setCursor(x, y); + if (charEdit) device->cursor(); + else device->blink(); + } + return 0; + } + + }; + + }//namespace Menu + + #endif +#endif