Adafruit NeoKey Trinkey

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
mahbub
 
Posts: 3
Joined: Fri Aug 19, 2022 4:27 am

Adafruit NeoKey Trinkey

Post by mahbub »

Hello,

A few days back, I bought some NeoKey Trinky! (https://www.adafruit.com/product/5020).

Currently, I'm running a code that will print out a coffee emoji. Sometimes, when I press the key, it will type something else (usually ee or e), not coffee. As a result, it prints out the wrong emoji. It usually happens when I press the key after a long time, and for consecutive strokes, it works fine.

Could you please look at my code and see what's wrong? I'm using the following code example:

https://github.com/adafruit/Adafruit_Le ... le/code.py

And here is the emoji code:
https://github.com/lifeparticle/Adafrui ... ji/code.py

Other info:
macOS Big Sur, Mac mini (M1, 2020)
adafruit-circuitpython-adafruit_neokey_trinkey_m0-en_GB-7.3.2.uf2

Kind regards,
Zaman

User avatar
FailingTinkerer
 
Posts: 9
Joined: Tue Dec 15, 2020 8:09 am

Re: Adafruit NeoKey Trinkey

Post by FailingTinkerer »

I suspect it's the character viewer that needs to be loaded into memory again. Basically, it has nothing to do with your script, but with how your OS handles keeping things in memory.

I suggest building in a 1-2 second delay if the key hasn't been activated for a while.

You can use time.monotic() for this purpose.
https://docs.circuitpython.org/en/lates ... .monotonic

User avatar
mahbub
 
Posts: 3
Joined: Fri Aug 19, 2022 4:27 am

Re: Adafruit NeoKey Trinkey

Post by mahbub »

Thank you for the explanation. Where in the code should I use the time.monotic() ? Can I use time.sleep instead?

User avatar
FailingTinkerer
 
Posts: 9
Joined: Tue Dec 15, 2020 8:09 am

Re: Adafruit NeoKey Trinkey

Post by FailingTinkerer »

You could use time.sleep(1) after you send the emojii board shortcut. (ctrl+command+space)

But that would always make it slow. It's worth a shot though to see if that solves the problem. After that you can use monotic to make it faster if it's been recently triggered.

Basically like this:

Code: Select all

import time

keypressed = 'whateveryour key gpio pin is'
start_time = time.monotonic()

while True:
    
    if keypressed == True:
        time_difference = time.monotonic() - start_time
        start_time = time.monotonic() # update the start_time to the last time the key was pressed
    
        if time_difference < 2000: # I think 2000 = 2 seconds, not sure. Figure out a time that works with your OS.
            #execute recently pressed code
            pass
        else:
            #execute hasn't been triggered in a while code
            pass
    
    time.sleep(1)

User avatar
mahbub
 
Posts: 3
Joined: Fri Aug 19, 2022 4:27 am

Re: Adafruit NeoKey Trinkey

Post by mahbub »

Thanks for the code example, I'll have a look. Thank you for your time!

Post Reply
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”