|
Post by powersoft on Jul 30, 2018 2:55:23 GMT -8
In this part I draw some keys to the screen. Is it posible to change the code in such a way that when I pressed a key only one event is generated? When I push the key now the values will be added for a couple of times. Would like the behaviour "on click => change the value"
Thanks for any help
/* draw buttons*/ GD.ColorRGB(WHITE); GD.Tag(1); //-1 GD.cmd_button( 50,200,50,25,27,OPT_CENTER,"-1"); GD.Tag(2); //-10 GD.cmd_button(105,200,50,25,27,OPT_CENTER,"-10"); GD.Tag(3); //-100 GD.cmd_button(160,200,50,25,27,OPT_CENTER,"-100");
GD.Tag(4); //+1 GD.cmd_button(250,200,50,25,27,OPT_CENTER,"+1"); GD.Tag(5); //+10 GD.cmd_button(305,200,50,25,27,OPT_CENTER,"+10"); GD.Tag(6); //+100 GD.cmd_button(360,200,50,25,27,OPT_CENTER,"+100");
GD.Tag(7); //quit GD.cmd_button(410,240,60,25,27,OPT_CENTER,"QUIT");
GD.swap(); GD.get_inputs(); if (GD.inputs.tag > 0) { Serial.print("tag : "); Serial.println(GD.inputs.tag); } if (GD.inputs.tag == 1) actual_unixtime -= 1; if (GD.inputs.tag == 2) actual_unixtime -= 10; if (GD.inputs.tag == 3) actual_unixtime -= 100; if (GD.inputs.tag == 4) actual_unixtime += 1; if (GD.inputs.tag == 5) actual_unixtime += 10; if (GD.inputs.tag == 6) actual_unixtime += 100; }
|
|
|
Post by jamesbowman on Jul 30, 2018 10:50:36 GMT -8
Right, the tag byte is a lot like a switch press before debouncing. The GD3 just reports continuous presses, and the host needs to filter out the button press event.
What I normally do is to keep a static variable holding the previous tag result.
static byte prev_tag; Then detecting a "first press" has an extra check that the previous tag was zero:
GD.get_inputs(); if (prev_tag == 0) { if (GD.inputs.tag > 0) { Serial.print("tag : "); Serial.println(GD.inputs.tag); } if (GD.inputs.tag == 1) actual_unixtime -= 1; if (GD.inputs.tag == 2) actual_unixtime -= 10; if (GD.inputs.tag == 3) actual_unixtime -= 100; if (GD.inputs.tag == 4) actual_unixtime += 1; if (GD.inputs.tag == 5) actual_unixtime += 10; if (GD.inputs.tag == 6) actual_unixtime += 100; } prev_tag = GD.inputs.tag;
|
|