Shop OBEX P1 Docs P2 Docs Learn Events
LCD appmod with the javelin — Parallax Forums

LCD appmod with the javelin

JamesJames Posts: 15
edited 2006-10-12 20:44 in General Discussion
I'm having trouble figuring out what exactly holds the values for when the buttons are pushed. for example with the example program when i press the left most button the character A shows up on the display. My question is where is that A so that i can change it to display a different variable, the variable will be a string.

is it something in this code, or in the LCDterminal class itself?
····· display.scroll(display.LINE1, msg);
····· display.write("Buttons:");
····· for(int i = 0; i < 150; i++) {
······· display.moveTo(display.LINE2, 2);
······· buttons = display.readButtons();
······· for (int mask, pos = 0x00; pos <= 0x03; pos += 1) {
········· mask = 0x001 << pos;
········· dispChar = ((buttons & mask) != 0) ? (65 + pos) : 45;
········· display.write(dispChar);}}

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-10-12 19:36
    The 'A' has ascii code 65 and this appears in this line:
    dispChar = ((buttons & mask) != 0) ? (65 + pos) : 45;

    which could also be written as
    dispChar = ((buttons & mask) != 0) ? ('A' + pos) : 45;

    When pos=1 then 'B' is displayed etc.

    regards peter
  • JamesJames Posts: 15
    edited 2006-10-12 20:26
    ok so with that established is there a recommended way of setting it so that when each individual button is pressed a different string variable will be outputted. like a case structure saying that when button1 (leftmost whatever that notation is that selects only that button) is pressed display the string variable soutput. and what code would be needed to allow this to occur for just one button. so that changes would only be needed for the button#. also is there a methodology so that when the button is pressed and released the value can be held on the display until a new button is pressed?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-10-12 20:44
    My guess is that there are up to 4 buttons.

    ····· display.scroll(display.LINE1, msg);
    ····· display.write("Buttons:");
    ····· for(int i = 0; i < 150; i++) {
    ······· display.moveTo(display.LINE2, 2);
    ······· buttons = display.readButtons();
    ······· for (int i=0; i<4; i++) {
    ··········int mask = buttons & (1<<i); //extract one bit each time
    ········· if (mask == 0) { //button pressed
    ··········· displayString(i);
    ·········· }
    ·········}
    ······· for (int mask, pos = 0x00; pos <= 0x03; pos += 1) {
    ········· mask = 0x001 << pos;
    ········· dispChar = ((buttons & mask) != 0) ? (65 + pos) : 45;
    ········· display.write(dispChar);}}

    static String[noparse]/noparse myStrings = new String[noparse]/noparse{"btn0","btn1","btn2","btn3"};

    static void displayString(int i) {
    · int j=0;
    · while (j < myStrings[noparse][[/noparse]i].length()) {
    ··· display.write(myStrings[noparse][[/noparse]i].charAt(j));
    ··· j++;
    · }
    }

    regards peter
Sign In or Register to comment.