|
Post by powersoft on Jan 20, 2017 11:19:37 GMT -8
Hello members,
I wont to catch a button. When pressed it should print out some text as an example. This is not working. What is wrong with my code?
Thanks for any help.
#include <SPI.h> #include <GD2.h>
void setup() { Serial.begin(115200); GD.begin(); }
void loop() { GD.ClearColorRGB(0x0000ff); GD.Clear(); GD.Tag(100); //next button has tag 100 GD.cmd_button(240,136,100,40,16,0,"Toggle"); GD.swap(); if (GD.inputs.tag==100) //button is pressed { Serial.println("Button pressed"); } }
|
|
dl14
Junior Member
Posts: 22
|
Post by dl14 on Jan 20, 2017 11:39:29 GMT -8
Try to initialize your button in setup()
The way you have it currently, you're re-creating a button over and over again. If you put it in the setup() it will only be made once and then you can get rid of the code that clears the screen - first two lines in your loop() method.
I also keep my serial at a rate of 9600 so you might want to try that out!
Hope this helps..
|
|
|
Post by powersoft on Jan 20, 2017 14:12:10 GMT -8
Thanks, but this is not working. When set the button in setup it wil never draws on the screen!
|
|
|
Post by powersoft on Jan 20, 2017 14:12:29 GMT -8
Thanks, but this is not working. When set the button in setup it wil never draws on the screen!
|
|
|
Post by tftlcdcyg on Jan 20, 2017 14:30:34 GMT -8
Try this:
#include <SPI.h> #include <GD2.h>
void setup() { Serial.begin(115200); GD.begin(); }
void loop() { GD.ClearColorRGB(0x0000ff); GD.Clear(); GD.get_inputs(); GD.Tag(100); //next button has tag 100 GD.cmd_button(140,136,200,80,16,0,"Toggle"); GD.Tag(255); if (GD.inputs.tag==100) //button is pressed { delay(105); GD.cmd_button(140,136,200,80,16,OPT_FLAT,"Pressed!"); Serial.println("Button pressed"); } GD.swap(); }
|
|