Hi
I have restructured your pde. My strong suggestion would be: Do not use GLCD directly, instead use m2tklib elements. I tried to mimic your GLCD output und transfered all to m2tklib code:
The code for this menu is quite simple and you still have a lot of features to control the output (".1" adds one digit after the comma, "f3" selects the big font, "c4" assigns 4 digits total)
M2_U32NUM(el_volt, ".1c5r1f3", &output_U1);
M2_LABEL(el_volt_label, NULL, "U.volt");
M2_U32NUM(el_ma, "c4r1f3", &output_amper);
M2_LABEL(el_ma_label, NULL, "mA");
M2_LIST(list_volt) = { &el_volt, &el_volt_label, &el_ma, &el_ma_label, &el_o1_go_back};
M2_GRIDLIST(top_el_volt, "c2", list_volt);
However, because of the PROGMEM feature discussed above, i modified m2tklib so you need an updated version (attached).
Please read your modified sourcecode. And please:
- Use m2tklib to output values
- Do not use delay()
Oliver
/*
SensorValues.pde
*/
/*==========================================================================*/
/* Includes and menu key definition */
/*==========================================================================*/
#include <glcd.h>
#include "M2tk.h"
#include "utility/m2ghglcd.h"
//#include "m2ghglcd.h"
unsigned long startMillis;
float opn=4.99; //??????? ?????????? ??????
float volt; // ?????????? ? ??????? ?????? ???????? ???????? ?????
float var0; // ?????? ????????????? ???????? ?????, ?????? ? ????????? ????? No0
int amper ; //?????????? ? ??????? ?????? ???????? ???????? ??????????.?????????? ????????????? ????????,? ?????? ??????? ??????????
float var1 ; // ?????? ????????????? ???????? ?????, ?????? ? ????????? ????? No1
//:: intoduced to communicate with m2tklib
uint32_t output_U1;
uint32_t output_amper;
//:: redefined to fit to my GLCD
uint8_t uiKeySelectPin = 3;
uint8_t uiKeyDownPin = 2;
uint8_t uiKeyUpPin = 1;
uint8_t uiKeyExitPin = 0;
/*==========================================================================*/
/* Sensor values: Will be set by some measurement processes */
/*==========================================================================*/
//:: removed, was part of the example
uint32_t value1 = 1;
uint32_t value2 = 2;
uint32_t value3 = 3;
/*==========================================================================*/
/* Active sensor: Output variable by the menu, shows active dialog box */
/*==========================================================================*/
/* 0: no sensor dialog open */
/* 1: sensor value 1 is on screen */
/* 2: sensor value 2 is on screen */
/* 3: sensor value 3 is on screen */
uint8_t active_sensor = 0;
/*==========================================================================*/
/* is_value_changed: Output variable by the sensor process */
/*==========================================================================*/
/* 0: value did not change */
/* 1: value has changed */
uint8_t is_value_changed = 0;
/*==========================================================================*/
/* Forward declaration of the menu class (required for the callback functions) */
/*==========================================================================*/
extern M2tk m2;
/*==========================================================================*/
/* Hierachical menu, go back button for each sensor value dialog */
/*==========================================================================*/
/*=== Forward declaration of the root menu for option 1 ===*/
M2_EXTERN_VLIST(top_el);
/*=== "Go Back" button, which will be reused for option 1 example menu ===*/
void fn_o1_go_back(m2_el_fnarg_p fnarg) {
active_sensor = 0;
m2.setRoot(&top_el);
}
M2_BUTTON(el_o1_go_back, NULL, "Go Back", fn_o1_go_back);
/*=== Dialog boxes to show the values ===*/
M2_U32NUM(el_volt, ".1c5r1f3", &output_U1);
M2_LABEL(el_volt_label, NULL, "U.volt");
M2_U32NUM(el_ma, "c4r1f3", &output_amper);
M2_LABEL(el_ma_label, NULL, "mA");
M2_LIST(list_volt) = { &el_volt, &el_volt_label, &el_ma, &el_ma_label, &el_o1_go_back};
M2_GRIDLIST(top_el_volt, "c2", list_volt);
M2_LABEL(el_o1_v2_desc, NULL, "LITR:");
M2_U32NUM(el_o1_v2_num, ".1c5r2", &value2);
M2_LIST(list_o1_v2) = { &el_o1_v2_desc, &el_o1_v2_num, &el_o1_go_back};
M2_VLIST(el_o1_v2_vlist, NULL, list_o1_v2);
M2_LABEL(el_o1_v3_desc, NULL, "GRADUS:");
M2_U32NUM(el_o1_v3_num, ".1c6r3", &value3);
M2_LIST(list_o1_v3) = { &el_o1_v3_desc, &el_o1_v3_num, &el_o1_go_back};
M2_VLIST(el_o1_v3_vlist, NULL, list_o1_v3);
/*=== A parent selection box allows to select one of the sensor values ===*/
void fn_o1_select1(m2_el_fnarg_p fnarg) {
active_sensor = 1;
m2.setRoot(&top_el_volt);
}
M2_BUTTON(el_o1_select1, NULL, "VOLTMETER", fn_o1_select1);
void fn_o1_select2(m2_el_fnarg_p fnarg) {
active_sensor = 2;
m2.setRoot(&el_o1_v2_vlist);
}
M2_BUTTON(el_o1_select2, NULL, "FUEL", fn_o1_select2);
void fn_o1_select3(m2_el_fnarg_p fnarg) {
active_sensor = 3;
m2.setRoot(&el_o1_v3_vlist);
}
M2_BUTTON(el_o1_select3, NULL, "TEMPERATURE", fn_o1_select3);
M2_LIST(list_o1) = { &el_o1_select1, &el_o1_select2, &el_o1_select3 };
M2_VLIST(top_el, NULL, list_o1);
/*==========================================================================*/
/* Menu constructor */
/*==========================================================================*/
M2tk m2(&top_el, m2_es_arduino, m2_eh_2bs, m2_gh_glcd_uffs);
/*==========================================================================*/
/* Sensor process */
/*==========================================================================*/
void volt_process(void) {
//:: introduce a temp variable, for the update flag
uint32_t tmp;
//:: avoid output to GLCD (conflicts with m2tklib), also use a separate process
// GLCD.Init(NON_INVERTED);
// GLCD.ClearScreen();
// GLCD.SelectFont((const uint8_t *)m2_System5x7);
// gText s1;gText s2;
//:: do not do any delays within the sensor process. It should return immediatly
// startMillis = millis();
// while( millis() - startMillis < 1000){
//:: again: do not do output to the GLCD directly
// s1.DefineArea(textAreaTOP);
// s1.SelectFont(fixednums15x31);
// s2.DefineArea(textAreaTOP);
// s2.SelectFont(fixednums15x31);
var0 = analogRead(0);
volt =(opn*var0/1024.0);
//:: value of U1 will be output on the screen. This should be done by m2tklib, so additionaly create output_U1
float U1;
U1=volt*((8200.0+1860.0)/1860.0)/2; //(opn*var1/1024.0)
//:: output_U1 is uint32_t, use "*10" to have one digit after the comma.
tmp = U1*10.0;
if ( output_U1 != tmp )
{
output_U1 = tmp;
is_value_changed = 1;
}
//:: Analog 1 is used by my GLCD
//var1 = analogRead(1);
float amper =((opn*var1/1.0240)/.50);
//:: same applies to "amber". I will introduce an uint32_t for the output of the amber value.
tmp = amper;
if ( output_amper != tmp )
{
output_amper = tmp;
is_value_changed = 1;
}
//:: remaining things are done by m2tklib
// s1.CursorTo(0,0);
// s1.print(U1);
// GLCD.SelectFont((const uint8_t *)m2_Arial14);
// GLCD.CursorTo(8,1);
// GLCD.Puts("U.volt");
// s2.CursorTo(0,1);
// s2.print(amper);
// GLCD.SelectFont((const uint8_t *)m2_Arial14);
// GLCD.CursorTo(8,3);
// GLCD.Puts("mA");
// delay(300);
// }
}
/* sensor3 process assignes a 1/10 seconds since reset */
void sensor3_process(void) {
uint32_t tmp;
/* just assign the 1/10 seconds since last reset */
tmp = millis();
tmp /= 100;
if ( value3 != tmp ) {
value3 = tmp;
is_value_changed = 1;
}
}
/* reads active_sensor and writes values to "value1", "value2" or "value3" */
void sensor_process(void)
{
switch(active_sensor) {
case 1:
volt_process();
break;
case 2:
break;
case 3:
break;
default:
break;
}
}
/*==========================================================================*/
/* Arduino setup & loop */
/*==========================================================================*/
void setup() {
pinMode(12, OUTPUT);
//:: pin 9 is used by my GLCD
// pinMode(9, OUTPUT);
m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
m2.setPin(M2_KEY_PREV, uiKeyUpPin);
m2.setPin(M2_KEY_EXIT, uiKeyExitPin);
// font 0 is for nomal text s
m2.setFont(0, m2_System5x7);
// font 3 a big sensor values
//m2.setFont(3, m2_System5x7);
m2.setFont(3, m2_fixednums7x15);
}
void loop() {
m2.checkKey();
if ( m2.handleKey() || is_value_changed ) {
m2.draw();
is_value_changed = 0;
}
sensor_process();
}
m2tklib_arduino_glcd_1.03pre1.zip (125 KB)