Facebook
From Reliable Meerkat, 4 Years ago, written in Plain Text.
This paste is a reply to Kod from Damian - view diff
Embed
Download Paste or View Raw
Hits: 241
  1. #include "U8glib.h"
  2. #include "M2tk.h"
  3. #include "m2ghu8g.h"
  4. #define EN 23
  5. #define RW 17
  6. #define RS 16
  7.  
  8.  
  9. // U8g setup
  10. U8GLIB_ST7920_128X64_1X lcd(EN, RW, RS);                  // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
  11.  
  12. // DOGM132, DOGM128 and DOGXL160 shield
  13. uint8_t uiKeyUpPin = 33;        
  14. uint8_t uiKeyBackPin = 31;
  15. uint8_t uiKeySelectPin = 35;
  16. uint8_t u;     /* the number, which was entered by the user */
  17. float srednica1;
  18. float srednica2;
  19. void fn_ok(m2_el_fnarg_p fnarg) {
  20.   /* do something with the number */
  21. }
  22.  
  23. M2_LABEL(el_goto_title, NULL, "Wybierz srednice");
  24. M2_LABEL(el_goto_title2, NULL, "filamenu:");
  25. M2_ROOT(el_goto_part1, NULL, "1.75", &srednica1);
  26. M2_ROOT(el_goto_part2, NULL, "2.85", &srednica2);
  27. M2_LIST(list_menu) = {&el_goto_title,&el_goto_title2, &el_goto_part1, &el_goto_part2,};
  28. M2_VLIST(el_menu_vlist, NULL, list_menu);
  29. M2_ALIGN(el_top, "W64H64", &el_menu_vlist);
  30. M2tk m2(&el_top, m2_es_arduino, m2_eh_4bs, m2_gh_u8g_bfs);
  31.  
  32. void draw(void) {
  33.     m2.draw();
  34. }
  35.  
  36. // Arduino setup procedure (called only once)
  37. void setup() {
  38.   // Connect u8glib with m2tklib
  39.   m2_SetU8g(lcd.getU8g(), m2_u8g_box_icon);
  40.  
  41.   // Assign u8g font to index 0
  42.   m2.setFont(0, u8g_font_7x13);
  43.   // Setup keys
  44.   m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
  45.   m2.setPin(M2_KEY_NEXT, uiKeyUpPin);
  46.   m2.setPin(M2_KEY_PREV, uiKeyBackPin);
  47.  
  48. }
  49. void loop() {
  50.   m2.checkKey();
  51.   if ( m2.handleKey() ) {
  52.     lcd.firstPage();  
  53.     do {
  54.       m2.checkKey();
  55.       draw();
  56.     } while( lcd.nextPage() );
  57.   }
  58.  
  59. }