Hi, sorry newbie her.
I’m wondering how do i build a nice live data library, and even maybe MP3 control.
I have the Arduino Mega 2560, Seeed MP3 shield and a momentary twist & push button with the ST7920 128x64 dotmatrix display in Serial link.
I can’t figure out how i implement live data in f.ex. the Engine Temps directory.
Live data code on a “non-menu” environment.
void draw(void) {
int OilTemp = analogRead(0);
float v_out = (OilTemp*5)/1023;
// show on the LCD the temperature
float temperature = (v_out*34)-40;
char temp[5];
dtostrf(temperature,3,1,temp);
u8g.drawStr(1,1,"Oil-Temp.");
u8g.drawStr(82,1,temp);
u8g.drawStr(108,1,"\260C");
And wondering how to change the Volume Value in audio via first “Select (pin26) then scroll (Prev/Next) Pin 28/24”
I’ve gotten as far as this:
/*
MenuX2L.pde
U8glib Example
m2tklib = Mini Interative Interface Toolkit Library
*/
#include <stdlib.h> // for itoa
#include "U8glib.h"
#include "M2tk.h"
#include "utility/m2ghu8g.h"
U8GLIB_ST7920_128X64 u8g(52, 51, 10, U8G_PIN_NONE);
//=================================================
// Variables for Menu Process
uint8_t uiKeyUpPin = 28;
uint8_t uiKeyDownPin = 24;
uint8_t uiKeySelectPin = 26;
uint8_t uiKeyExitPin = 0;
//=================================================
// Forward declaration of the toplevel element
M2_EXTERN_ALIGN(top_el_x2l_menu);
//=================================================
// Define three user menus.
M2_ROOT(el_mnu1_sel, "t1", "Engine Teperatures", &top_el_x2l_menu);
M2_ALIGN(top_el_mnu1_sel, "-1|1W64H64", &el_mnu1_sel);
M2_ROOT(el_mnu2_sel, "t1", "AFR & Speeds" , &top_el_x2l_menu);
M2_ALIGN(top_el_mnu2_sel, "-1|1W64H64", &el_mnu2_sel);
M2_ROOT(el_mnu3_sel, "t1", "Driving Values", &top_el_x2l_menu);
M2_ALIGN(top_el_mnu3_sel, "-1|1W64H64", &el_mnu3_sel);
//=================================================
uint8_t value = 0;
char buf[20];
// define callback procedure, which returns a menu entry with a value
const char *xmenu_value(uint8_t idx, uint8_t msg) {
if ( msg == M2_STRLIST_MSG_SELECT ) {
value++;
}
if ( msg == M2_STRLIST_MSG_GET_STR ) {
strcpy(buf, " Volume: ");
itoa((int)value, buf+strlen(buf), 10);
return buf;
}
return "";
}
// define callback procedures which increment and decrement a value
const char *xmenu_dec(uint8_t idx, uint8_t msg) {
if ( msg == M2_STRLIST_MSG_SELECT ) {
value--;
}
return "";
}
const char *xmenu_play(uint8_t idx, uint8_t msg) {
if ( msg == M2_STRLIST_MSG_SELECT ) {
value--;
}
return "";
}
const char *xmenu_stop(uint8_t idx, uint8_t msg) {
if ( msg == M2_STRLIST_MSG_SELECT ) {
value--;
}
return "";
}
const char *xmenu_next(uint8_t idx, uint8_t msg) {
if ( msg == M2_STRLIST_MSG_SELECT ) {
value--;
}
return "";
}
const char *xmenu_prev(uint8_t idx, uint8_t msg) {
if ( msg == M2_STRLIST_MSG_SELECT ) {
value--;
}
return "";
}
//=================================================
// this is the overall menu structure for the X2L Menu
m2_xmenu_entry xmenu_data[] =
{
{ "Audio", NULL, NULL }, /* expandable main menu entry */
{ ".", NULL, xmenu_value }, /* The label of this menu line is returned by the callback procedure */
{ ". Decrease", NULL, xmenu_dec }, /* This callback decrements the value */
{ ". Play/Pause", NULL, xmenu_play },
{ ". Stop", NULL, xmenu_stop },
{ ". Next", NULL, xmenu_next },
{ ". Preveous", NULL, xmenu_prev },
{ "ViPec V88", NULL, NULL },
{ ". Engine Temps", &top_el_mnu1_sel, NULL },
{ ". AFR & Speed", &top_el_mnu2_sel, NULL},
{ ". Driving Values", &top_el_mnu3_sel, NULL },
{ NULL, NULL, NULL },
};
//=================================================
// This is the main menu dialog box
// The first visible line and the total number of visible lines.
// Both values are written by M2_X2LMENU and read by M2_VSB
uint8_t el_x2l_first = 0;
uint8_t el_x2l_cnt = 3;
// M2_X2LMENU definition
// Option l4 = four visible lines
// Option e15 = first column has a width of 15 pixel
// Option W43 = second column has a width of 43/64 of the display width
// Option F3 = select font 3 for the extra column (icons)
M2_X2LMENU(el_x2l_strlist, "l4e15W43F3", &el_x2l_first, &el_x2l_cnt, xmenu_data, 65,102,'\0');
M2_SPACE(el_x2l_space, "W1h1");
M2_VSB(el_x2l_vsb, "l4W2r1", &el_x2l_first, &el_x2l_cnt);
M2_LIST(list_x2l) = { &el_x2l_strlist, &el_x2l_space, &el_x2l_vsb };
M2_HLIST(el_x2l_hlist, NULL, list_x2l);
M2_ALIGN(top_el_x2l_menu, "-1|1W64H64", &el_x2l_hlist);
//=================================================
// m2 object and constructor
M2tk m2(&top_el_x2l_menu, m2_es_arduino, m2_eh_4bs, m2_gh_u8g_ffs);
//=================================================
// Draw procedure, Arduino Setup & Loop
void draw(void) {
m2.draw();
}
void setup(void) {
// Connect u8glib with m2tklib
m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);
// Assign u8g font to index 0
m2.setFont(0, u8g_font_6x13r);
// Assign icon font to index 3
m2.setFont(3, u8g_font_m2icon_7);
// Setup keys
m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
m2.setPin(M2_KEY_PREV, uiKeyUpPin);
m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
m2.setPin(M2_KEY_EXIT, uiKeyExitPin);
/*
m2.setPin(M2_KEY_SELECT, 7);
m2.setPin(M2_KEY_ROT_ENC_A, 3);
m2.setPin(M2_KEY_ROT_ENC_B, 4);
*/
}
void loop() {
// menu management
m2.checkKey();
if ( m2.handleKey() != 0 ) {
u8g.firstPage();
do {
m2.checkKey();
draw();
} while( u8g.nextPage() );
}
pinMode(9, OUTPUT);
analogWrite(9, 155);
}