Spirik / GEM

Good Enough Menu for Arduino
GNU Lesser General Public License v3.0
239 stars 36 forks source link

Encoder or/and 4x4_over_i2c_multiplexer #61

Closed Furbysz closed 9 months ago

Furbysz commented 1 year ago

Howdy. First of all, this lib is very nice, seems easy to use and I couldn't find many others that can use SPI 128x64 display.

But back on the topic. I wanted to use it in my project with uses quite a lot of pins rn on its own. Soo reusing 7 just for menu when i have already 16 keys on 4x4 keyboard, thats plugged into i2c multiplexer, soo actually it uses 2 pins of micro controler. I tought using 2 rotary encoders will do the trick, with they didn't becouse of how they work.

Soo i tought if there is a way of doing it, or easy way to implement those funcionalities directlly. Mebe by using something like functions insead of pins. like instead of pin 6 being home/cancel, calling GEM_cancel() would do same.

Thanks in advance.

shezik commented 1 year ago

This could help. https://github.com/Spirik/GEM/wiki/How-to#control-menu-from-your-sketch

Spirik commented 1 year ago

Hi, @Furbysz ! Yes, @shezik is correct, technically you can use whichever input device you have, just register its keypresses (or whatever action) in your own sketch and manually trigger GEM::registerKeyPress() method accordingly.

Here is an example of controlling GEM via Serial (roughly inspired by KeyDetector library) that may help to get a basic idea of how to write custom control for your menu.

Furbysz commented 1 year ago

Lokks like clean solution :)

Will take a while to test it tho, code i've wrote doesnt want to work, i wipl post it when i get on my pc.

It combines fastLED, GEM and Keyboard over i2c to probide menu that can be used to select led and change its R, G, and B values.

FastLed and keyboard didnt seem to make problems before, soo i guess its something with gem not working with my setup. I will add mire info when i get on PC.

Other clue can be that im using ESP32 dev module.

Spirik commented 1 year ago

That is possible. There are reports of incompatibility with some ESP32 boards: sketch may compile and upload just fine, but issues appear during runtime.

Furbysz commented 1 year ago

Well, id did not compiled at all. Was screaming at me that it couldnt find AltSerialGraphicLCD, after i installed it... SoftwareSerial.h not found. ffs. INSTALL.... used arduino_740163 instad of arduino_979120 whatever those are. i relocated 740... elsewhere soo it must use 979... Couldnt find avr/interrupt.h

This is a downwards spiral lmao

Spirik commented 1 year ago

Yes, ESP32 boards do not tolerate AltSerialGraphicLCD library, however you can exclude support for this library prior to compile (by manually editing config.h file or by setting build flags). See the following Readme sections for details:

Furbysz commented 1 year ago

Seems like it did a trick. It started working. Out of curiosity tho. Can one make menu options programically?

Like when ESP lunches it checks for files on SD card and puts them as options in separate menu. Soo when you select in menu "test1.wav" it plays this file.

Spirik commented 1 year ago

Yes, it should be possible to create menu items in a loop, based on some content (in your case - the count of files on SD card). You can specify the same callback for these menu items, and pass parameter to it to determine which menu item was actually activated (in your case it can be the name of an audio file).

Please see this post with a basic example on how to achieve that (the whole thread was about dynamic menu items creation, and with the latest GEM update it became possible).

Spirik commented 11 months ago

👋 FYI: just updated GEM with examples on how to control menu with rotary encoder using latest version of KeyDetector