Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #include <LiquidCrystal_I2C.h>
- #include "M2tk.h"
- #include "utility/m2ghnlc.h"
- LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- unsigned long Interval; // milliseconds between updates
- unsigned long lastUpdate; // last update of position
- // BUTTONS //
- uint8_t uiKeySelectPin = 4;
- uint8_t uiKeyNextPin = 5;
- uint8_t uiKeyPrevPin = 6;
- //uint8_t uiKeyUpPin = 7;
- // M2TKLIB STUFF //
- const char *selected = "Nothing";
- const char *el_strlist_getstr(uint8_t idx, uint8_t msg) {
- const char *s = "";
- if ( idx == 0 )
- s = "Apple";
- else if ( idx == 1 )
- s = "Banana";
- else if ( idx == 2 )
- s = "Peach";
- else if ( idx == 3 )
- s = "Pumpkin";
- else if ( idx == 4 )
- s = "Corn";
- if (msg == M2_STRLIST_MSG_GET_STR) {
- /* nothing else todo, return the correct string */
- } else if ( msg == M2_STRLIST_MSG_SELECT ) {
- selected = s;
- }
- return s;
- }
- uint8_t el_strlist_first = 0;
- uint8_t el_strlist_cnt = 5;
- M2_STRLIST(el_strlist, "l3w12", &el_strlist_first, &el_strlist_cnt, el_strlist_getstr);
- //M2_SPACE(el_space, "w1h1");
- M2_VSB(el_strlist_vsb, "l3w1r1", &el_strlist_first, &el_strlist_cnt);
- M2_LIST(list_strlist) = { &el_strlist,/* &el_space,*/ &el_strlist_vsb };
- M2_HLIST(el_strlist_hlist, NULL, list_strlist);
- M2_SPACE(el_vspace, "w1h1");
- M2_LABEL(el_label, NULL, "Selected:");
- M2_LABELPTR(el_labelptr, NULL, &selected);
- M2_LIST(list_label) = { &el_label, &el_labelptr };
- M2_HLIST(el_label_hlist, NULL, list_label);
- M2_LIST(list) = { &el_strlist_hlist, /*&el_vspace,*/ &el_label_hlist };
- M2_VLIST(el_vlist, NULL, list);
- M2_ALIGN(top_el, "-1|1W64H64", &el_vlist);
- M2tk m2(&top_el, m2_es_arduino, m2_eh_4bs, m2_gh_nlc);
- void effectselect()
- {
- if ((millis() - lastUpdate) > Interval) // time to update
- {
- lastUpdate = millis();
- if (selected == "Apple")
- {
- Serial.print(selected);
- }
- if (selected == "Banana")
- {
- Serial.print(selected);
- }
- if (selected == "Peach")
- {
- Serial.print(selected);
- }
- if (selected == "Pumpkin")
- {
- Serial.print(selected);
- }
- if (selected == "Corn")
- {
- Serial.print(selected);
- }
- }
- }
- void setup() {
- Serial.begin(9600);
- m2_SetNewLiquidCrystal(&lcd, 20, 4);
- m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
- m2.setPin(M2_KEY_NEXT, uiKeyNextPin);
- m2.setPin(M2_KEY_PREV, uiKeyPrevPin);
- // m2.setPin(M2_KEY_DATA_UP, uiKeyUpPin);
- }
- void loop() {
- effectselect();
- if ( m2.handleKey() )
- m2.draw();
- m2.checkKey();
- }
Advertisement
Add Comment
Please, Sign In to add comment