Adafruit GFX Library

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Mosto
 
Posts: 2
Joined: Wed Jun 02, 2021 2:24 am

Adafruit GFX Library

Post by Mosto »

Hi everyone.
In the Arduino example sketch of the telephone keypad, by holding down the same number button, in the text box where the number appears, the new number is accepted only after releasing and pressing the key again. I would like that by holding down the same numeric key, in the text box the number pressed would be added to the previous one every time. For example, if I leave button 1 pressed, "1", then "11", then "111" etc. appear sequentially in the text box.
I tried with the function of the Adafruit_GFX_Button Class isPressed (void), but it didn't work. Is there anyone who can point me to a working example of this.
Thanks in advance and sorry for my English.
Regards.

User avatar
blnkjns
 
Posts: 963
Joined: Fri Oct 02, 2020 3:33 am

Re: Adafruit GFX Library

Post by blnkjns »

I think for this to work as you like, we need to write a custom routine to do the readout. What is the frequency of your loop routine? Does it loop like 30-100 times a second, or is there a big delay in it? If that is the case, you need a timer or a pin interrupt to do the key reading. What board do you use?
Can you give the exact part number of your keypad?

User avatar
Mosto
 
Posts: 2
Joined: Wed Jun 02, 2021 2:24 am

Re: Adafruit GFX Library

Post by Mosto »

@blnkjns
Thank you for your answer.
I use an Arduino Mega with a 3.5 "TFT 320x480, which communicates with serial to an Arduino Due.
The loop must be 250 milliseconds. I have to solve this because I'm going to apply the logic of this type of routine to a button that increases the speed of a stepper motor. The code, very simple, has already been written, but I can only increase the speed by releasing and pressing the button again.
The only critical piece of code is the following. The Arduino Mega sends the command to the Arduino Due, which in turn controls the engine. The increase is calculated by the arduino due, based on the string received by the arduino Mega.

Code: Select all

for (uint8_t b = 0; b < 4; b++) {
    if (buttonsTrack[b].justReleased()) {
      buttonsTrack[b].drawButton(); 
    }
    if (buttonsTrack[b].justPressed()) {
      buttonsTrack[b].drawButton(true); 
  
      // Custom Speed -- Speed decreases 
      if (b == 0) {
             Serial1.print (":GG-#");
        // Go to Sidereal Track
       
      }

     // Custom Speed ++ Speed Up
      if (b == 1) {
          Serial1.print (":GG+#");
     
       }
      
      // Run/Stop step --
      if (b == 2) {
         Serial1.print (":SM#");
       
      }
    }
     
   delay(1); // UI debouncing
  }
Thanks in advance.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”