Hello, I need your help. can anyone have an example code for a graphical display

So far only happened since. Clicking OK runs a program. When you cancel the second program runs.

*/

#include <glcd.h>		// inform Arduino IDE that we will use GLCD library
#include "M2tk.h"
#include "utility/m2ghglcd.h"


uint8_t uiKeySelectPin = 4;
uint8_t uiKeyDownPin = 3;
uint8_t uiKeyUpPin = 2;
uint8_t uiKeyExitPin = 1;

uint8_t select_color = 0;
uint8_t select_priority = 0;
uint8_t is_voltmeter = 0;
uint8_t is_fuel = 0;


void fn_ok(m2_el_fnarg_p fnarg) { 
  digitalWrite(8, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(8, LOW);    // set the LED off
  delay(10); tone(6, 440, 200); is_voltmeter = 1; is_fuel = 0;           // wait for a second
  /* accept selection */
}

void fn_cancel(m2_el_fnarg_p fnarg) {
  digitalWrite(8, HIGH);   // set the LED on
  delay(100);              // wait for a second
  digitalWrite(8, LOW);    // set the LED off
  delay(10);tone(6, 140, 200); is_voltmeter = 0; is_fuel = 1;              // wait for a second
  /* discard selection */
}

const char *fn_idx_to_color(uint8_t idx)
{
  if ( idx == 0 )
    return "red";
  else if (idx == 1 )
    return "green";
  return "temp";tone(6, 740, 200);
  
}

const char *fn_idx_to_priority(uint8_t idx)
{
  switch(idx)
  {
    case 0: return "lowest";tone(6, 150, 200);
    case 1: return "low";tone(6, 140, 200);
    case 2: return "medium";tone(6, 130, 200);
    case 3: return "high";tone(6, 120, 200);
    
  }
  return "";
}
M2_LABEL(el_label1, NULL, "voltmeter");
M2_RADIO(el_radio1, "v0", &select_color);

M2_LABEL(el_label2, NULL, "fuel");
M2_RADIO(el_radio2, "v0", &select_color);

M2_LABEL(el_label3, NULL, "Color:");
M2_COMBO(el_combo3, NULL, &select_color, 3, fn_idx_to_color);

M2_LABEL(el_label4, NULL, "Priority: ");
M2_COMBO(el_combo4, "v1", &select_priority, 4, fn_idx_to_priority);

M2_BUTTON(el_cancel, NULL, "cancel", fn_cancel);
M2_BUTTON(el_ok, NULL, " ok ", fn_ok);

M2_LIST(list) = {
    &el_label1, &el_radio1, 
    &el_label2, &el_radio2, 
    &el_label3, &el_combo3, 
    &el_label4, &el_combo4,  
    &el_cancel, &el_ok 
};
M2_GRIDLIST(list_element, "c2",list);
M2tk m2(&list_element, m2_es_arduino, m2_eh_4bs, m2_gh_glcd_ffs);

void voltmeter_process(void) {
  digitalWrite(9, HIGH);  // set the LED on 
  delay(500);
  digitalWrite(9, LOW);  // set the LED off
  delay(200);
  digitalWrite(9, HIGH);  // set the LED on 
  delay(500);
  digitalWrite(9, LOW);   // set the LED off
}
void fuel_process(void) {
  digitalWrite(12, HIGH);  // set the LED on 
  delay(50);
  digitalWrite(12, LOW);  // set the LED off
  delay(20);
  digitalWrite(12, HIGH);  // set the LED on 
  delay(50);
  digitalWrite(12, LOW);   // set the LED off
}



void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
   pinMode(12, 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);  
}

void loop() {
  m2.checkKey();
  if ( m2.handleKey() ) {
      m2.draw();
  }
  if ( is_voltmeter )
  voltmeter_process ();


if ( is_fuel )
  fuel_process ();
}

But I guess it's too complicated for my level of knowledge. I'm very sorry sad.

Don't be sad. I guess it is more a learning curve. Working with C or C++ in an embedded environment is complicated.

For the first part of my answer, i looked up some resources on finite state machine design for embedded systems.

This one is nice, because it covers the "creative step":
http://ceit.uq.edu.au/content/finite-state-machine-design-so-whats-problem-why-cant-students-get-it

This tutorial is more related to embedded programming:
http://www.splatco.com/fsm_tute/fsm_tute01.htm

I am not sure how to teach you on embedded software design, but maybe you get some ideas from the above links.

second, more specific answer to your problem follows later...

Oliver

So, here is the second part of my answer...

This is what i understand from your problem:

  • There are three things to measure (three sensor values)
  • You want to be able to select between these measurements (one dialog box for each sensor value)
    Your questions might be:
  1. How to construct a menu hierarchy for selecting a measurement
  2. How to write a program so that measurement and menu (m2tklib) are working in parallel.

Answer for 1)
The example below offers three different ways to select between the three sensor values.

  • section menu,
  • bottom menu bar or
  • combo box menu.
    So you can see the differences between them, when you compile and download the example code.

Answer for 2)
I have added a parallel process for the measurement. Menu and measurement processes are working together through global variables (see code for details).
As an example,

  • sensor value 1 toggles between 0 and 1
  • sensor value 2 does nothing (and has the constant value 2)
  • sensor value 3 shows 1/10 seconds since reset.

The code below should compile fine on your Arduino Environment:
See Google Code Archive - Long-term storage for Google Code Project Hosting. or attachment of this reply.

Oliver

SensorValues.pde (11.3 KB)

Thank you very much for helping me. :slight_smile:

Hello, your code is the menu I liked. So I decided to apply it. Until just wanted to add the program to a voltmeter. But this compilation is a mistake . I tried all the libraries glcd. And I can not understand what was happening. :~ ?:arduino/-022/libraries/glcd/fonts/systemFont5x7.h:48 error: System5x7 causes a section type conflict
?:arduino/-022/libraries/glcd/fonts/fixednums15x31.h:23 error: fixednums15x31 causes a section type conflict
?:arduino/-022/libraries/glcd/fonts/Arial_14.h:55 error: Arial_14 causes a section type conflict

/*


  SensorValues.pde


  Provide two alternative ways to show three sensor values.


  GLCD Example


  m2tklib = Mini Interative Interface Toolkit Library
  
  Copyright (C) 2011  olikraus@gmail.com
  
  
  /*==========================================================================*/
/* Includes and menu key definition */
/*==========================================================================*/


#include "M2tk.h"
#include "utility/m2ghglcd.h"
#include "glcd.h"
#include "fonts/allFonts.h"

 unsigned long startMillis;
 
 float opn=4.99;     //??????? ?????????? ??????
 float volt;         // ?????????? ? ??????? ?????? ???????? ???????? ?????              
 float var0;            // ?????? ????????????? ???????? ?????, ?????? ? ????????? ????? ?0  
 int amper ;          //?????????? ? ??????? ?????? ???????? ???????? ??????????.?????????? ????????????? ????????,? ?????? ??????? ??????????
 float var1  ;        // ?????? ????????????? ???????? ?????, ?????? ? ????????? ????? ?1


uint8_t uiKeySelectPin = 4;
uint8_t uiKeyDownPin = 3;
uint8_t uiKeyUpPin = 2;
uint8_t uiKeyExitPin = 1;


/*==========================================================================*/
/* Sensor values: Will be set by some measurement processes  */
/*==========================================================================*/


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;


/*==========================================================================*/
/* Option 1:  Hierachical menu, go back button for each sensor value dialog */
/*==========================================================================*/


/*=== Forward declaration of the root menu for option 1 ===*/ 
M2_EXTERN_VLIST(el_o1_vlist);


/*=== "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(&el_o1_vlist); 
}
M2_BUTTON(el_o1_go_back, NULL, "Go Back", fn_o1_go_back);


/*=== A simple dialog box, which shows the value ===*/ 
/*
  +==============+
  | Description: |
  | 0000.0       |
  | [Go Back]    |
  +==============+
  three menus will be defined, one for each sensor value 
*/


M2_LABEL(el_o1_v1_desc, NULL, "VOLTS");
M2_U32NUM(el_o1_v1_num, ".1c4r1", &value1);
M2_LIST(list_o1_v1) = { &el_o1_v1_desc, &el_o1_v1_num, &el_o1_go_back};
M2_VLIST(el_o1_v1_vlist, NULL, list_o1_v1);


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(&el_o1_v1_vlist); 
}
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(el_o1_vlist, NULL, list_o1);

M2_ROOT(el_goto_o1, NULL, "Option 1: Parent Menu", &el_o1_vlist);
void fn_o2_start(m2_el_fnarg_p fnarg) { 
  active_sensor = 1; 
  
}
M2_LIST(list_options) = { &el_goto_o1  };
M2_VLIST(el_options, NULL, list_options);
/*==========================================================================*/
/* Menu constructor */
/*==========================================================================*/


M2tk m2(&el_options, m2_es_arduino, m2_eh_2bs, m2_gh_glcd_ffs);
  
  /*==========================================================================*/
/* Sensor process */
/*==========================================================================*/


/* sensor1 process assignes state of a flashing LED */


uint8_t led_state = 0;
uint32_t next_change = 0;
uint8_t is_flashing = 0;
uint8_t flash_delay = 7;


void sensor1_process(void) {
  // wait until timer as expired
  if ( next_change < millis() ) {
    if ( led_state == 0 ) {
      digitalWrite(12, HIGH);  // set the LED on    
      led_state = 1;
    } else {
      digitalWrite(12, LOW);   // set the LED off
      led_state = 0;
    }
    // wait for x*50ms, were x is between 0 and 9
    next_change = millis() + (flash_delay*50L);
  } 
  if ( led_state != value1 ) {
    value1 = led_state;
    is_value_changed = 1;
  }
}


/* sensor1 process does nothing program voltmeter*/


void sensor2_process(void) {
  
  
 GLCD.Init(NON_INVERTED);   // initialise the library, non inverted writes pixels onto a clear screen
   GLCD.ClearScreen(); 
   GLCD.SelectFont(System5x7);
 gText s1;gText s2;
  
      startMillis = millis();
  while( millis() - startMillis < 1000){
 s1.DefineArea(textAreaTOP);
 s1.SelectFont(fixednums15x31);
 s2.DefineArea(textAreaTOP);
 s2.SelectFont(fixednums15x31);
 
 

var0 = analogRead(0); //?????????? ??? ?????? ?????? ? ??????????? ?????              
  volt =(opn*var0/1024.0);//????????? ?????????? ?? ????? ? ???????? 
  float U1;         //?????? ?????????????? ?????????? ???? ?????????? ?????????? ????? ????????
  U1=volt*((8200.0+1860.0)/1860.0)/2;  //(opn*var1/1024.0)???????? ??????? ?????????? ?? ????? ??????????
   
    var1 = analogRead(1);//???? ??? ??????????              
    amper =((opn*var1/1.0240)/.50); //???????? ?????????? ? ???????????? ? ????? ?? .50 -????????????? ?????,???????? ???????? ?????????? ? ????????????

    

    
    
    s1.CursorTo(0,0);//?????? ?????? ? ???????? ????? ????.
    s1.print(U1); //??????? ??????????? ???????? ?? ????? 
    GLCD.SelectFont(Arial_14);//?????????? ????? ??????? ?????
    GLCD.CursorTo(8,1);//?????? ?????? ? ???????
    GLCD.Puts("U.volt");//??????? ??????? U.volt
   
    
    s2.CursorTo(0,1);
    s2.print(amper);
    GLCD.SelectFont(Arial_14);
    GLCD.CursorTo(8,3);
    GLCD.Puts("mA");
    
    delay(300); //????????-?????????? ?????? 3 ???? ? ???????   
}
}
   
   

  
  
  



/* 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:
      sensor1_process();
      break;
    case 2:
      sensor2_process();
      break;
    case 3:
      sensor3_process();
      break;
    default:
      break;
  }
}


/*==========================================================================*/
/* Arduino setup & loop */
/*==========================================================================*/


void setup() {
  
  pinMode(12, OUTPUT); 
  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);  
}


void loop() {
  m2.checkKey();
  if ( m2.handleKey() || is_value_changed ) {
      m2.draw();
      is_value_changed = 0;
  }
  
  sensor_process();
}

I'm really stumped on that one too.
The error shows up whenever a call to SelectFont() is done
down in sensor2_process().

Something very odd (but probably dirt simple) is causing this strange error.
(Still working on locating the issue)

UPDATE:

The problem shows up when using the M2_BUTTON() macro.
I'm not an expert (actually I know pretty much nothing about ) about gcc attributes, so I can't say what was intended with the
parent macro definition of M2_SECTION_PROGMEM
It is defined as

#define M2_SECTION_PROGMEM __attribute__((section(".progmem.data")))

Other references to attribute that use progmem don't define it that way.
If I change the definition to simply reference the AVR definition PROGMEM instead, the error goes away.
i.e.:

#define M2_SECTION_PROGMEM PROGMEM

PROGMEM is defined in the system headers as:

#define __ATTR_PROGMEM__ __attribute__((__progmem__))
#define PROGMEM __ATTR_PROGMEM__

note the difference.
I'm guessing progmem is a "magic" attribute name?

Oliver, can you take a look at this?

--- bill

Oh, I saw these replies too late.

I am using a different definition of M2_SECTION_PROGMEM to a void a g++ compiler bug, which produces a c++ warning:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734

Using

#define M2_SECTION_PROGMEM PROGMEM

would be the better definition. The purpose is to put as much as possible of the data into flash rom area.

However, as far as I remember the GLCD API, the problem could be caused by the inclusion of the font files. Arial and SystemFont are also included within m2tklib. So including them again with

#include "fonts/allFonts.h"

will fail: I guess, because the font definition is in the .h file itself, so you get a double definition.

Fixing this error:
replace

#include "fonts/allFonts.h"

with

#include "fonts/fixednums15x31.h"

(whatever other fonts you need, do explicitly include them)

Also replace

GLCD.SelectFont(System5x7);

with

GLCD.SelectFont(m2_System5x7);

and do the same with the Arial font. As I said, System and Arial (and only these two!) are included already in m2tklib. See also here:
http://code.google.com/p/m2tklib/wiki/ghref#m2_gh_glcd_ubf

@Bill: If I could request an enhancement for GLCD: Please allow multiple inclusion of font files from different C/C++ sources.

@alexssey163: Another issue in the code is, that you do another init in the sensor_process.
This will init the GLCD very often and in parallel to m2tklib (which also does the GLCD.init)
It is simply not required and it might conflict with m2tklib (two parallel tasks will use the same resource). I also do not know what will happen if you do the init for GLCD multiple times.

I will try to compile and review the code in the next days.

Oliver

here are some fast code updates from my side, but still produce the conflict error. But i think, this is because of the g++ bug. The GLCD fonts also use PROGMEM, which might lead to the gcc bug under certain condition.
My suggestion would be: First, try to write your program without fixednums. Use the system or Arial font instead (m2_...). If all other things are working, then we could try to switch to fixednums again.

/*
  SensorValues.pde

  /*==========================================================================*/
/* Includes and menu key definition */
/*==========================================================================*/


#include "M2tk.h"
#include "utility/m2ghglcd.h"
//#include "m2ghglcd.h"
#include "glcd.h"
#include "fonts/fixednums15x31.h"

 unsigned long startMillis;
 
 float opn=4.99;     //??????? ?????????? ??????
 float volt;         // ?????????? ? ??????? ?????? ???????? ???????? ?????              
 float var0;            // ?????? ????????????? ???????? ?????, ?????? ? ????????? ????? No0  
 int amper ;          //?????????? ? ??????? ?????? ???????? ???????? ??????????.?????????? ????????????? ????????,? ?????? ??????? ??????????
 float var1  ;        // ?????? ????????????? ???????? ?????, ?????? ? ????????? ????? No1


uint8_t uiKeySelectPin = 4;
uint8_t uiKeyDownPin = 3;
uint8_t uiKeyUpPin = 2;
uint8_t uiKeyExitPin = 1;


/*==========================================================================*/
/* Sensor values: Will be set by some measurement processes  */
/*==========================================================================*/


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;


/*==========================================================================*/
/* Option 1:  Hierachical menu, go back button for each sensor value dialog */
/*==========================================================================*/


/*=== Forward declaration of the root menu for option 1 ===*/ 
M2_EXTERN_VLIST(el_o1_vlist);


/*=== "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(&el_o1_vlist); 
}
M2_BUTTON(el_o1_go_back, NULL, "Go Back", fn_o1_go_back);


/*=== A simple dialog box, which shows the value ===*/ 
/*
  +==============+
  | Description: |
  | 0000.0       |
  | [Go Back]    |
  +==============+
  three menus will be defined, one for each sensor value 
*/


M2_LABEL(el_o1_v1_desc, NULL, "VOLTS");
M2_U32NUM(el_o1_v1_num, ".1c4r1", &value1);
M2_LIST(list_o1_v1) = { &el_o1_v1_desc, &el_o1_v1_num, &el_o1_go_back};
M2_VLIST(el_o1_v1_vlist, NULL, list_o1_v1);


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(&el_o1_v1_vlist); 
}
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(el_o1_vlist, NULL, list_o1);

M2_ROOT(el_goto_o1, NULL, "Option 1: Parent Menu", &el_o1_vlist);
void fn_o2_start(m2_el_fnarg_p fnarg) { 
  active_sensor = 1; 
  
}
M2_LIST(list_options) = { &el_goto_o1  };
M2_VLIST(el_options, NULL, list_options);
/*==========================================================================*/
/* Menu constructor */
/*==========================================================================*/


M2tk m2(&el_options, m2_es_arduino, m2_eh_2bs, m2_gh_glcd_ffs);
  
  /*==========================================================================*/
/* Sensor process */
/*==========================================================================*/


/* sensor1 process assignes state of a flashing LED */


uint8_t led_state = 0;
uint32_t next_change = 0;
uint8_t is_flashing = 0;
uint8_t flash_delay = 7;


void sensor1_process(void) {
  // wait until timer as expired
  if ( next_change < millis() ) {
    if ( led_state == 0 ) {
      digitalWrite(12, HIGH);  // set the LED on    
      led_state = 1;
    } else {
      digitalWrite(12, LOW);   // set the LED off
      led_state = 0;
    }
    // wait for x*50ms, were x is between 0 and 9
    next_change = millis() + (flash_delay*50L);
  } 
  if ( led_state != value1 ) {
    value1 = led_state;
    is_value_changed = 1;
  }
}


/* sensor1 process does nothing program voltmeter*/


void sensor2_process(void) {
  
  
 GLCD.Init(NON_INVERTED);   // initialise the library, non inverted writes pixels onto a clear screen
   GLCD.ClearScreen(); 
   GLCD.SelectFont((const uint8_t *)m2_System5x7);
 gText s1;gText s2;
  
      startMillis = millis();
  while( millis() - startMillis < 1000){
 s1.DefineArea(textAreaTOP);
 s1.SelectFont(fixednums15x31);
 s2.DefineArea(textAreaTOP);
 s2.SelectFont(fixednums15x31);
 
 

var0 = analogRead(0); //?????????? ??? ?????? ?????? ? ??????????? ?????              
  volt =(opn*var0/1024.0);//????????? ?????????? ?? ????? ? ???????? 
  float U1;         //?????? ?????????????? ?????????? ???? ?????????? ?????????? ????? ????????
  U1=volt*((8200.0+1860.0)/1860.0)/2;  //(opn*var1/1024.0)???????? ??????? ?????????? ?? ????? ??????????
   
    var1 = analogRead(1);//???? ??? ??????????              
    amper =((opn*var1/1.0240)/.50); //???????? ?????????? ? ???????????? ? ????? ?? .50 -????????????? ?????,???????? ???????? ?????????? ? ????????????

    

    
    
    s1.CursorTo(0,0);//?????? ?????? ? ???????? ????? ????.
    s1.print(U1); //??????? ??????????? ???????? ?? ????? 
    GLCD.SelectFont((const uint8_t *)m2_Arial14);//?????????? ????? ??????? ?????
    GLCD.CursorTo(8,1);//?????? ?????? ? ???????
    GLCD.Puts("U.volt");//??????? ??????? 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); //????????-?????????? ?????? 3 ???? ? ???????   
}
}
   
   

  
  
  



/* 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:
      sensor1_process();
      break;
    case 2:
      sensor2_process();
      break;
    case 3:
      sensor3_process();
      break;
    default:
      break;
  }
}


/*==========================================================================*/
/* Arduino setup & loop */
/*==========================================================================*/


void setup() {
  
  pinMode(12, OUTPUT); 
  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);  
}


void loop() {
  m2.checkKey();
  if ( m2.handleKey() || is_value_changed ) {
      m2.draw();
      is_value_changed = 0;
  }
  
  sensor_process();
}

olikraus:
Oh, I saw these replies too late.

I am using a different definition of M2_SECTION_PROGMEM to a void a g++ compiler bug, which produces a c++ warning:
34734 – [4.2/4.3/4.5/4.6 Regression][avr] attribute((progmem)) not handled properly in C++

Using

#define M2_SECTION_PROGMEM PROGMEM

would be the better definition. The purpose is to put as much as possible of the data into flash rom area.

When I modified the M2_SECTION_PROGMEM defintion to use PROGMEM
The errors in his sketch go away and the code compiled and seem to run ok.
Does the alternate progmem definition cause issues when the avr supplied PROGMEM attribute is used?

However, as far as I remember the GLCD API, the problem could be caused by the inclusion of the font files. Arial and SystemFont are also included within m2tklib. So including them again with

#include "fonts/allFonts.h"

will fail: I guess, because the font definition is in the .h file itself, so you get a double definition.

I don't think it should fail
(haven't tried including a font header multiple times in different modules in quite some time though)
What I noticed in the past was that you potentially get duplicate copies of the font data
included in your final linked image as the data arrays are declared as "static".
(more about this below)

Fixing this error:
replace

#include "fonts/allFonts.h"

with

#include "fonts/fixednums15x31.h"

(whatever other fonts you need, do explicitly include them)

You must mean for the fonts that are not used by m2.
If he included say something that m2 includes, like say the System5x7 font,
I bet he's right back to the same as including "allFonts.h".

Also replace

GLCD.SelectFont(System5x7);

with

GLCD.SelectFont(m2_System5x7);

and do the same with the Arial font. As I said, System and Arial (and only these two!) are included already in m2tklib. See also here:
Google Code Archive - Long-term storage for Google Code Project Hosting.

This does not seem like a good thing. It is mixing data definitions from one API and using it another API.
My suggestion is that if m2 must have its own font declarations, then m2 should have an API call to handle it
and not push its definition through the GLCD API.
i.e it seems like users should be calling m2_gh_glcd_set_font() rather than GLCD.SelectFont()

@Bill: If I could request an enhancement for GLCD: Please allow multiple inclusion of font files from different C/C++ sources.

Yep. I agree that this is currently a really bad deficiency.
It is a well known issue.
And while I totally ditest many things about the current font files and the actual font data
format, it is a major change to correct this. Michael and I discussed this at
great length when were working on v3. We went back and forth on correcting this a few times.
The problem is that as you have seen the data is declared in the .h file. It really should
be in .c files and then have .h file(s) to declare the references to them.
When it is only in header files, if you eliminate the static definition you get
duplicate names and the link fails. With the static you don't get errors and
everything will work but the actual font data ends up being included each time the header is included
in a module.
This is not particularly easy thing to correct and automate in the goofy Arduino IDE world,
and especially on non *nix platforms where you don't have much for real s/w tools available.
I did look at correcting this in v3, but eventually decided to abandon it due
to so many issues with the IDE and trying to keep it simple for Arduino users.
It is also somewhat tied into Thiele's FontCreator2 tool. It generates these font header files.
(It requires an updated FontCreator tool to generate new font files)
There are also some other things that I'd like to fix in the font data format as well
that would simplify the font rendering code.
(Thiele incorrectly shifted bits to the wrong end of a byte when the residual data is less than 8 bits in a byte)
But to make these any of these changes would have broken backward compatibility with v2
which was a very high priority
so Michael and I decided to defer any of those kinds of changes to a future major
update release.
It is definitely something on my list to get resolved as I've been burned by it as well,
especially when using normal Makefiles and C/C+ code vs the Arduino IDE environment.

@alexssey163: Another issue in the code is, that you do another init in the sensor_process.
This will init the GLCD very often and in parallel to m2tklib (which also does the GLCD.init)
It is simply not required and it might conflict with m2tklib (two parallel tasks will use the same resource). I also do not know what will happen if you do the init for GLCD multiple times.

While not necessary, calling the init routine multiple times should not be an issue.
I haven't done extensive testing on it, but the GLCD library is supposed to handle calling Init() multiple times.
There is no memory that is allocated that will be lost. I have tested it by looping hundreds of times to ensure that
it seems to work, but that is about all the testing I have done but I don't anticipate any issues with calling
the initialization routine more than once.

--- bill

Hello, thank you for your explanation :).

Hello, I have two questions. How to make so I can come back from any of the programs back on the menu. I do not even appears on "goback".
program temperature sensor1 works not stable readings are flashing. I'll try to find out myself but also on aid will not give up. Thank you.

All the code does not fit :~. Please answer only if the first question.

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)

Thank you very much. You helped me a lot. :slight_smile:

Hello, I'm not comfortable asking you yet. :blush: We can make big numbers fixednums15x31. I just have a second program are displayed, fuel level of graphics. Code below to program fuel.

//   Fuel Meter v1.0 
// Author : Robotix & RJ
// Date: 21 November 2010
// Property of : ROBOMODS
#include "glcd.h"
#include "fonts/allFonts.h"
const int analogPin = 0;     // potentiometer wiper (middle terminal) connected to analog pin 3
                     // outside leads to ground and +5V
int raw = 0;                 // variable to store the raw input value
int Vin = 5;                 // variable to store the input voltage
float Vout = 0;              // variable to store the output voltage
float R1 = 48;               // variable to store the R1 value
float R2 = 0;                // variable to store the R2 value
float buffer = 0;            // buffer variable for calculation
const int ledMediumL = 7;   // Lower Range Value for Medium Fuel
const int ledMediumH = 48;   // Upper Range Value for Medium Fuel
const int ledPin = 12;      // Set Medium Fuel LED to Pin 12
const int ledLowH = 4;      // Upper Range Value for Low Fuel (Anything below this is obviously Low Fuel)
const int ledPin2 = 2; // Set Low Fuel LED to Pin 2
long lastsec = 1; // must be different from sec for initial update

void setup()
{ GLCD.Init(NON_INVERTED);
  GLCD.ClearScreen();
  
  Serial.begin(9600);             // Setup serial         
  pinMode(ledPin, OUTPUT);        // Set Medium Fuel LED Pin to OUTPUT
  pinMode(ledPin2, OUTPUT);        // Set Low Fuel LED Pin to OUTPUT
}
void BarGraph(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t fullval, uint8_t currentval){
unsigned int currentwidth = currentval * width / fullval;
#ifdef SAMPLE_MAP
unsigned int currentwidth = map(currentval, 0, fullval, 0, width);
#endif

	GLCD.DrawRect(x, y, width, height);		// draw boarder
	GLCD.FillRect(x, y, currentwidth, height);	// draw left "busy" part
	GLCD.FillRect(x+currentwidth+1, y+1, width-currentwidth-2, height-2, WHITE); // clear right part
}

gText t1; // will define runtime later

#if DISPLAY_HEIGHT > 32

#endif


void loop()
{
  int raw = analogRead(analogPin);    // Reads the Input PIN
  Vout = ((5.0 / 5115.0) * raw);    // Calculates the Voltage on the Input PIN
  buffer = (Vin / Vout) - 1;      
  R2 = R1 / buffer;
  R2 = R2 * 4;
  Serial.print("Resistance: ");           // Prints the Resistance Label
  Serial.println(R2);
        t1.DefineArea(textAreaTOP);
	t1.SelectFont(fixednums15x31);  // Prints the Resistance Value
     t1.CursorToXY(0,0);
     
     t1.print(R2);
     BarGraph(10, 40, 108, 16, 59, R2);
     lastsec = R2; // save last update time
     GLCD.SelectFont(System5x7);
     GLCD.CursorTo(0,6);//?????? ?????? ? ???????
     GLCD.Puts("L");
     GLCD.CursorTo(18,6);//?????? ?????? ? ???????
     GLCD.Puts("H");
     
     
     
  
if (R2 > ledMediumL) {                 // Check if Fuel is within Medium Range
  if (R2 < ledMediumH) {                // Checl if Fuel is within Medium Range
   digitalWrite(ledPin, HIGH);           // It is so turn on Medium Fuel LED
   Serial.print("Medium Fuel! ");        // Tell the Console
}
   else {
     digitalWrite(ledPin, LOW);           // It isn't so make sure the Medium Fuel LED is OFF
}
  }
  else {
    digitalWrite(ledPin, LOW);           // It isn't so make sure the Medium Fuel LED is OFF
    if (R2 <= ledLowH) {              // Check if fuel is below the Low Fuel Threshold
      digitalWrite(ledPin2, HIGH);        // It is so turn on the Low Fuel LED
      Serial.print("Low Fuel! ");        // Tell the Console
    }
    else {
      digitalWrite(ledPin2, LOW);         // It isn't so make sure the Low Fuel LED is OFF
    }
}

  delay(1000);                       // Pause to allow for more accurate reading
}

Hi

I have attached pre2 of m2tklib. It includes the new label m2_fixednums15x3, which can be
used to assign the font to some index:
m2.setFont(2, m2_fixednums15x31);

You can select this font by using f2 (where 2 is the index)
M2_U32NUM(el_volt, ".1c5r1f**2**", &output_U1);

Note: M2tklib v1.03pre2 has not been tested very much.

Oliver

m2tklib_arduino_glcd_1.03pre2.zip (125 KB)

As always, thank you very much dear olikraus . :slight_smile:

Hello, tell me how to get the temperature from the sensor on the graphic screen. I have something that does not work. I can not back when you return to the menu. What am I doing wrong please help. :~
I do not understand why I can not send the entire code. =(

#include "glcd.h"
#include "fonts/allFonts.h"
#include "M2tk.h"
#include "utility/m2ghglcd.h"
#include <Bounce.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 9

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;
// function that will be called when an alarm condition exists during DallasTemperatures::processAlarms();
void newAlarmHandler(uint8_t* deviceAddress)
{
  Serial.println("Alarm Handler Start"); 
  printAlarmInfo(deviceAddress);
  printTemp(deviceAddress);
  Serial.println();
  Serial.println("Alarm Handler Finish");
}

void printCurrentTemp(DeviceAddress deviceAddress)
{
  printAddress(deviceAddress);
  printTemp(deviceAddress);
  Serial.println();
}

void printAddress(DeviceAddress deviceAddress)
{
  Serial.print("Address: ");
  for (uint8_t i = 0; i < 8; i++)
  {
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
  Serial.print(" ");
}

void printTemp(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC != DEVICE_DISCONNECTED)
  {
    Serial.print("Current Temp C: ");
    Serial.print(tempC);
  }
  else Serial.print("DEVICE DISCONNECTED");
  Serial.print(" ");
}

void printAlarmInfo(DeviceAddress deviceAddress)
{
  char temp;
  printAddress(deviceAddress);
  temp = sensors.getHighAlarmTemp(deviceAddress);
  Serial.print("High Alarm: ");
  Serial.print(temp, DEC);
  Serial.print("C");
  Serial.print(" Low Alarm: ");
  temp = sensors.getLowAlarmTemp(deviceAddress);
  Serial.print(temp, DEC);
  Serial.print("C");
  Serial.print(" ");
}




//#include "m2ghglcd.h"

 unsigned long startMillis;
 
 
 
 
//:: intoduced to communicate with m2tklib
uint32_t output_U1;
uint32_t output_amper;
uint32_t output_L1;
uint32_t output_L2;
uint32_t output_tempC;

//:: redefined to fit to my GLCD
uint8_t uiKeySelectPin = 40;
uint8_t uiKeyDownPin = 41;
uint8_t uiKeyUpPin = 38;
uint8_t uiKeyExitPin = 39;
//::  removed, was part of the example
uint32_t value1 = 1;
uint32_t value2 = 2;
uint32_t value3 = 3;
uint32_t value4 = 4;
uint32_t value5 = 5;
/* 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; 
/* 0: value did not change */
/* 1: value has changed */
uint8_t is_value_changed = 0; 

extern M2tk m2;

/*=== 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_li3, ".1c4r1f2", &output_tempC);
M2_LIST(list_o1_v5) = { &el_li3,  &el_o1_go_back};
M2_VLIST(el_o1_v5_vlist, NULL, list_o1_v5);
/*=== 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); 
             }
void fn_o1_select5(m2_el_fnarg_p fnarg) { 
  active_sensor = 5; 
  m2.setRoot(&el_o1_v5_vlist); 
}
M2_BUTTON(el_o1_select5, NULL, "TEMPERATURE", fn_o1_select5);
M2_LIST(list_o1) = { &el_o1_select1, &el_o1_select2, &el_o1_select3 , &el_o1_select4 , &el_o1_select5 };
M2_VLIST(top_el, NULL, list_o1);
M2tk m2(&top_el, m2_es_arduino, m2_eh_4bs, m2_gh_glcd_uffs);
  
void volt_process(void) { //I can not send all the code. So cut.
  }
    
/* fuel process. */
void celsi_process(void) { 
 
void lever_process(void) {  
}
  
void temper_process(void) {
  uint32_t tmp;
   
  // ask the devices to measure the temperature
  sensors.requestTemperatures();
  
  // if an alarm condition exists as a result of the most recent 
  // requestTemperatures() request, it exists until the next time 
  // requestTemperatures() is called AND there isn't an alarm condition
  // on the device
  if (sensors.hasAlarm())
  {
    Serial.println("Oh noes!  There is at least one alarm on the bus.");
  }

  // call alarm handler function defined by sensors.setAlarmHandler
  // for each device reporting an alarm
  sensors.processAlarms();

  if (!sensors.hasAlarm())
  {
    // just print out the current temperature
    printCurrentTemp(insideThermometer);
    printCurrentTemp(outsideThermometer);
  }
  float tempC;
   tmp = tempC;
    if ( output_tempC != tmp )
    {
      output_tempC = tmp;
      is_value_changed = 1;
  delay(50);
  
}
}
/* 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:
    celsi_process();
      break;
    case 4:
    lever_process();
    break;
   case 5:
    temper_process();
    
    default:
      break;
  }
}
void setup() {
  
   // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
  
  // locate devices on the bus
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // search for devices on the bus and assign based on an index
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1"); 

  Serial.print("Device insideThermometer ");
  printAlarmInfo(insideThermometer);
  Serial.println();
  
  Serial.print("Device outsideThermometer ");
  printAlarmInfo(outsideThermometer);
  Serial.println();
  
  // set alarm ranges
  Serial.println("Setting alarm temps...");
  sensors.setHighAlarmTemp(insideThermometer, 61);
  sensors.setLowAlarmTemp(insideThermometer, 91);
  sensors.setHighAlarmTemp(outsideThermometer, 60);
  sensors.setLowAlarmTemp(outsideThermometer, 90);
  
  Serial.print("New insideThermometer ");
  printAlarmInfo(insideThermometer);
  Serial.println();
  
  Serial.print("New outsideThermometer ");
  printAlarmInfo(outsideThermometer);
  Serial.println();

  // attach alarm handler
  sensors.setAlarmHandler(&newAlarmHandler);

  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(2, m2_fixednums15x31);
  
  pinMode(switchPin4, INPUT); //dipped headlights
  pinMode(ledPin4, OUTPUT); 
  
  pinMode(BUTTON,INPUT);//High beams
  pinMode(LED,OUTPUT);
   
  
  pinMode(controlPin, OUTPUT); 
  pinMode(ledPin, OUTPUT);        // Set Medium Fuel LED Pin to OUTPUT
  pinMode(ledPin2, OUTPUT);   // Set Low Fuel LED Pin to OUTPUT
}
boolean debounce(boolean last)
{
  boolean current =digitalRead(switchPin4 );
  if (last !=current)
  {
    delay(5);
    current = digitalRead(switchPin4 );
  }
  return current;
}

   void BarGraph(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t fullval, uint8_t currentval){
   GLCD.Init(INVERTED); 
unsigned int currentwidth = currentval * width / fullval;
#ifdef SAMPLE_MAP
unsigned int currentwidth = map(currentval, 0, fullval, 0, width);
#endif
        
	GLCD.DrawRect(x, y, width, height);		// draw boarder
	GLCD.FillRect(x, y, currentwidth, height);	// draw left "busy" part
	GLCD.FillRect(x+currentwidth+1, y+1, width-currentwidth-2, height-2, WHITE); // clear right part 
}
void loop() {
  if ( bouncer.update() ) {
     if ( bouncer.read() == HIGH) {
       if ( ledValue == LOW ) {
         ledValue = HIGH;
       } else {
         ledValue = LOW;
       }
       digitalWrite(LED,ledValue);
     }
   }
   currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledOn =!ledOn;
  }
  lastButton = currentButton;
  digitalWrite(ledPin4, ledOn);
   
  m2.checkKey();
  if ( m2.handleKey() || is_value_changed ) {
      m2.draw();
      is_value_changed = 0;
  }
  
  sensor_process();
}

Hi

I do not understand why I can not send the entire code.

You could use the "additional options..." and attach your .pde file.

tell me how to get the temperature from the sensor on the graphic screen

Which is the variable which holds the temperature value?
I am a little bit confused about the source. Maybe you cut some important parts.
Maybe you can attach the whole source.

Oliver

Hello, thank you. I have attached a file pde. It is completely code. If you're wondering what I can tell you that this will be my first on-board computer. I have a very old mazda323 1986 all wiring is very old and puts stress. The engine cooling fan is working badly. And Money on another machine there. So I decided to put this device. temperature sensor on the idea of ?two wanted to put it. in a salon in another engine. but still wanted to look at one.

on_board_computer_1.pde (16.2 KB)

A real cool application. A nice project.

I have checked your source. And the code seems to be fine for me.
Maybe you could more detailed specify what you expect and what is wrong with your code.
I could help better if you could describe the problem more detailed.

You mentioned the temperature:
active_sensor is set to 5, fine
output_tempC is set, however the delay(1000) will freeze your display for 1 second!

Are other sensors working? Is your menu ok?

Oliver

Oliver