Guest User

Arduino Sketch

a guest
Jun 19th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include <FastLED.h>
  2. #include <LiquidCrystal_I2C.h>
  3. #include "M2tk.h"
  4. #include "utility/m2ghnlc.h"
  5.  
  6. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  7.  
  8. unsigned long Interval; // milliseconds between updates
  9. unsigned long lastUpdate; // last update of position
  10.  
  11. // BUTTONS //
  12. uint8_t uiKeySelectPin = 4;
  13. uint8_t uiKeyNextPin = 5;
  14. uint8_t uiKeyPrevPin = 6;
  15. //uint8_t uiKeyUpPin = 7;
  16.  
  17. // M2TKLIB STUFF //
  18. const char *selected = "Nothing";
  19. const char *el_strlist_getstr(uint8_t idx, uint8_t msg) {
  20. const char *s = "";
  21. if ( idx == 0 )
  22. s = "Apple";
  23. else if ( idx == 1 )
  24. s = "Banana";
  25. else if ( idx == 2 )
  26. s = "Peach";
  27. else if ( idx == 3 )
  28. s = "Pumpkin";
  29. else if ( idx == 4 )
  30. s = "Corn";
  31. if (msg == M2_STRLIST_MSG_GET_STR) {
  32. /* nothing else todo, return the correct string */
  33. } else if ( msg == M2_STRLIST_MSG_SELECT ) {
  34. selected = s;
  35. }
  36.  
  37. return s;
  38.  
  39. }
  40.  
  41. uint8_t el_strlist_first = 0;
  42. uint8_t el_strlist_cnt = 5;
  43. M2_STRLIST(el_strlist, "l3w12", &el_strlist_first, &el_strlist_cnt, el_strlist_getstr);
  44. //M2_SPACE(el_space, "w1h1");
  45. M2_VSB(el_strlist_vsb, "l3w1r1", &el_strlist_first, &el_strlist_cnt);
  46. M2_LIST(list_strlist) = { &el_strlist,/* &el_space,*/ &el_strlist_vsb };
  47. M2_HLIST(el_strlist_hlist, NULL, list_strlist);
  48.  
  49. M2_SPACE(el_vspace, "w1h1");
  50. M2_LABEL(el_label, NULL, "Selected:");
  51. M2_LABELPTR(el_labelptr, NULL, &selected);
  52. M2_LIST(list_label) = { &el_label, &el_labelptr };
  53. M2_HLIST(el_label_hlist, NULL, list_label);
  54.  
  55. M2_LIST(list) = { &el_strlist_hlist, /*&el_vspace,*/ &el_label_hlist };
  56. M2_VLIST(el_vlist, NULL, list);
  57. M2_ALIGN(top_el, "-1|1W64H64", &el_vlist);
  58.  
  59. M2tk m2(&top_el, m2_es_arduino, m2_eh_4bs, m2_gh_nlc);
  60.  
  61. void effectselect()
  62. {
  63. if ((millis() - lastUpdate) > Interval) // time to update
  64. {
  65. lastUpdate = millis();
  66. if (selected == "Apple")
  67. {
  68. Serial.print(selected);
  69. }
  70. if (selected == "Banana")
  71. {
  72. Serial.print(selected);
  73. }
  74. if (selected == "Peach")
  75. {
  76. Serial.print(selected);
  77. }
  78. if (selected == "Pumpkin")
  79. {
  80. Serial.print(selected);
  81. }
  82. if (selected == "Corn")
  83. {
  84. Serial.print(selected);
  85. }
  86. }
  87. }
  88.  
  89. void setup() {
  90. Serial.begin(9600);
  91. m2_SetNewLiquidCrystal(&lcd, 20, 4);
  92. m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
  93. m2.setPin(M2_KEY_NEXT, uiKeyNextPin);
  94. m2.setPin(M2_KEY_PREV, uiKeyPrevPin);
  95. // m2.setPin(M2_KEY_DATA_UP, uiKeyUpPin);
  96.  
  97. }
  98.  
  99. void loop() {
  100. effectselect();
  101. if ( m2.handleKey() )
  102. m2.draw();
  103. m2.checkKey();
  104. }
Advertisement
Add Comment
Please, Sign In to add comment