Pages: 1 [2] 3 4   Go Down
Author Topic: Hello, I need your help. can anyone have an example code for a graphical display  (Read 8999 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
I electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is your program. example from the library M2tklib_arduino_glcd_1.02
I wanted to try your example of http://code.google.com/p/m2tklib/wiki/t01glcd. And now generates this error
Logged

Help me please

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 74
Posts: 7255
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK. It was not my program. Someone else wrote this library and program. I'll try it sometime after work to see what happened. I have thought about trying it but was distracted by other projects.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 36
I electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks I'll look forward to your reply.
Logged

Help me please

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1516
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

From what i see in your error message i would assume that this is more a problem with the GLCD library itself and not with m2tklib.

The device handler m2ghglcdubf.cpp has been written for GLCDv3 from here:
http://code.google.com/p/glcd-arduino/
It seems that GLCDv3 is based on
http://www.pjrc.com/teensy/td_libs_GLCD.html
however there was major rework on GLCDv3.

To solve the problem you might switch to GLCDv3 or do some changes in m2ghglcdubf.cpp.
For your current error it might be sufficient to put an explicit cast in line 51:
51: GLCD.Puts((char *)(arg->s));
but my fear is, that this is not the only difference between GLCDv2 and GLCDv3

Oliver

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
I electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much you were right. smiley
Logged

Help me please

Dallas, TX USA
Offline Offline
Faraday Member
**
Karma: 70
Posts: 2738
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

From what i see in your error message i would assume that this is more a problem with the GLCD library itself and not with m2tklib.

The device handler m2ghglcdubf.cpp has been written for GLCDv3 from here:
http://code.google.com/p/glcd-arduino/
It seems that GLCDv3 is based on
http://www.pjrc.com/teensy/td_libs_GLCD.html
however there was major rework on GLCDv3.

To solve the problem you might switch to GLCDv3 or do some changes in m2ghglcdubf.cpp.
For your current error it might be sufficient to put an explicit cast in line 51:
51: GLCD.Puts((char *)(arg->s));
but my fear is, that this is not the only difference between GLCDv2 and GLCDv3

Oliver



Actually GLCD v3 is simply a major update to the ks0108 library:
http://www.arduino.cc/playground/Code/GLCDks0108
That is why GLCD is v3 vs v1. (ks0108 was at v2)
The name changed from ks0108 to GLCD because it now supports more than the ks0108.
Paul has a modified version of Michaels ks0108 v2 library on his Teensy site that he modified to
make it easier to configure for his Teensy boards.
I would not recommend using that library at this point in time. Use GLCD v3.
GLCD v3 has support for the Teensy/Teensy++ boards "out of the box" using the recommend
glcd wiring on Pauls Teensy site.

Michael and I worked very hard to try to maintain full backward compatibility
with v2. There are a few minor incompatibilities but they quite small and are documented
in the documentation that comes with the v3 library as well as how to migrate your existing
ks0108 v2 code to GLCD v3.
Also with v3 not only are there many new features but it is much faster and has support
for the Mega 2560.

--- bill
« Last Edit: August 19, 2011, 02:58:15 am by bperrybap » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
I electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, please tell me how to code. eg choose red low click well. and starts to run my program. such as LED lights.

Code:
/*

  Combo.pde
 
  GLCD Example

  m2tklib = Mini Interative Interface Toolkit Library
 
  Copyright (C) 2011  olikraus@gmail.com

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#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;

void fn_ok(m2_el_fnarg_p fnarg) {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
  /* accept selection */
}

void fn_cancel(m2_el_fnarg_p fnarg) {
  digitalWrite(13, HIGH);   // set the LED on
  delay(100);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(100);              // 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";
 
}

const char *fn_idx_to_priority(uint8_t idx)
{
  switch(idx)
  {
    case 0: return "lowest";
    case 1: return "low";
    case 2: return "medium";
    case 3: return "high";
    case 4: return "1";
    case 5: return "2";
    case 6: return "3";
    case 7: return "4";
    case 8: return "5";
  }
  return "";
}


M2_LABEL(el_label1, NULL, "Color:");
M2_COMBO(el_combo1, NULL, &select_color, 3, fn_idx_to_color);

M2_LABEL(el_label2, NULL, "Priority: ");
M2_COMBO(el_combo2, "v1", &select_priority, 8, 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_combo1,
    &el_label2, &el_combo2, 
    &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 setup() {
  pinMode(13, 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();
  }
}

I do not understand how to make smiley-sad
« Last Edit: August 19, 2011, 02:42:30 pm by alexssey163 » Logged

Help me please

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1516
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I do not understand how to make

I am not sure that I fully understand your question. Do you mean the "make" process: Compile and upload. This is my suggested procedure:

1. Installed GLCDv3 from http://code.google.com/p/glcd-arduino
2. Download and install m2tklib for GLCDv3 (m2tklib_arduino_glcd_1.02.zip )
3. Start the Arduino IDE. m2tklib examples should appear here: File->Examples->m2tklib
4. Check some of the examples: Load the "combo" example into the Arduino IDE, compile and upload the sketch. You should be able to see the following picture on your display

5. Save the combo sketch under a different name and start coding. Use the Arduino IDE to compile and upload your code.

According to your code: Selecting "cancel" or "ok" will put the output pin 13 on high state for 1/10 of a second (not one second as mentioned in the comment, because delay assumes milliseconds).

Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
I electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, I would like to modify the sample. Make it so that when you click OK, I started flashing LED. And when you click cancel to stop flashing. I do not understand what should be changed so as to do so.
Logged

Help me please

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1516
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, let us assume you want to start flashing when you select "ok" and stop flashing with "cancel".

Most important: You will need to think of two independent processes. One process displays and manages the menu. The other process is responsible for flashing. Let us start with the flashing process. We need a procedure which can be called and handles the flashing:

Code:
void flashing_process(void);
Additionally there must be some external variables, the LED state (on and off) and the time for the next state change.
Code:
uint8_t led_state = 0;
uint32_t next_change = 0;
So the flashing process might look light this:
Code:
void flashing_process(void) {
  // wait until timer as expired
  if ( next_change < millis() ) {
    if ( led_state == 0 ) {
      digitalWrite(13, HIGH);  // set the LED on   
      led_state = 1;
    } else {
      digitalWrite(13, LOW);   // set the LED off
      led_state = 0;
    }
    // wait for 100ms
    next_change = millis() + 100;
  }
}
This process could be used inside the Arduino-loop():
Code:
void loop() {
  flashing_process();
}

So, back to the problem: The flashing should be turned on and off: So we need another variable:
Code:
uint8_t is_flashing = 0;
Flashing can be controlled in this way:
Code:
void loop() {
  if ( is_flashing )
    flashing_process();
}
Flashing will be off, if is_flashing contains a zero. Now, let the menu modify the is_flashing variable. Use the "ok" and "cancel" callback procedures for this:
Code:
void fn_ok(m2_el_fnarg_p fnarg) {
  is_flashing = 1;
}
void fn_cancel(m2_el_fnarg_p fnarg) {
  is_flashing = 0;
}

Finally you have to put the menu process and the flashing process together:
Code:
void loop() {
  // this is the menu management process
  m2.checkKey();
  if ( m2.handleKey() ) {
      m2.draw();
  }
  // this is the flashing process
  if ( is_flashing )
    flashing_process();
}

Conclusion: It is important to think of two independent things happen in parallel: Menu handling and flashing. Clearly separate these tasks in the Arduino-loop. The Arduino-loop itself acts like a scheduler for your processes.

Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
I electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, I'm beginning to understand.
Logged

Help me please

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1516
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I put things together and created a .pde file. It is available here:

http://code.google.com/p/m2tklib/source/browse/arduino/glcd/LEDFlash/LEDFlash.pde

Additionally I added a field to the menu which controls the flash frequency.

Oliver
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1516
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also note, that tutorial 4 (http://code.google.com/p/m2tklib/wiki/t04) on the m2tklib wiki also demonstrates parallel processes: The menu system controls a state machine which implements a simple game. Menu system and state machine of the game are implemented as independent processes. Both processes are called inside the Arduino loop().

Thank you for the nice example on Menu and LED flashing. 

Oliver
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
I electronics
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tell me how to make hello world label. In another place the screen in this example smiley-confuse
Code:
#include <glcd.h> // inform Arduino IDE that we will use GLCD library
#include "M2tk.h"
#include "utility/m2ghglcd.h"


M2_LABEL(hello_world_label, "f0", "MAZDA 323 FOREVER");
M2tk m2(&hello_world_label, NULL , NULL, m2_gh_glcd_bf);

void setup() {
}

void loop() {
  m2.draw();
  delay(500);
}
Logged

Help me please

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1516
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have several options:

The align element defines a box. One sub-element can be aligned to any edge of the box.
Code:
M2_LABEL(el_label, "f0", "Text");
M2_ALIGN(el_align, "w128h64|2-2", &el_label);
M2tk m2(&el_align, NULL , NULL, m2_gh_glcd_bf);
Reference: http://code.google.com/p/m2tklib/wiki/elref#ALIGN

If elements are placed inside the xylist, then the x and y options of the sub-elements assign the lower left position of the element.
Code:
M2_LABEL(el_label, "x20y10f0", "Text");
M2_LIST(el_list) = { &el_label };
M2_XYLIST(el_xy, NULL, el_list);
M2tk m2(&el_xy, NULL , NULL, m2_gh_glcd_bf);
Reference: http://code.google.com/p/m2tklib/wiki/elref#XYLIST

Additionally, a text can be centered inside a label. Add 8 to the font option and use the w option for the intended width.
Code:
M2_LABEL(el_label, "w80f8", "Text");
M2tk m2(&el_label, NULL , NULL, m2_gh_glcd_bf);

All these methods can be combined.

Oliver
Logged

Pages: 1 [2] 3 4   Go Up
Jump to: