Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Feather M0 Express!
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Feather M0 Express!

by tannewt on Fri Jul 21, 2017 1:02 pm

Move these lines below the three after. Its what waits for the release.

Code: Select all | TOGGLE FULL SIZE
while (not button.value):
                pass  # wait for it to be released!

tannewt
 
Posts: 1845
Joined: Thu Oct 06, 2016 8:48 pm

Re: Feather M0 Express!

by adafruit2 on Fri Jul 21, 2017 1:40 pm

remove the

while (not button.value):
pass # wait for it to be released!

or move it to after the keypress is emitted

adafruit2
Site Admin
 
Posts: 19406
Joined: Fri Mar 11, 2005 7:36 pm

Re: Feather M0 Express!

by dhalbert on Fri Jul 21, 2017 2:44 pm

[edited to correct]

@KyleMohr: see code for loop below (tested). Note that I moved the keyboard press up, and also moved the time.sleep() inside the if. Note that you still have to wait for the button to be released. Otherwise holding down the button will cause the keypress to be sent over and over again. Also, the time.sleep(0.01) is important to "debounce" the button (detailed explanation here). The button will actually turn off and on several times before settling down when you press it. If the sleep() is too short, you may get multiple presses. I am using some buttons right now that require waiting for 200 msecs before they stop bouncing.

Code: Select all | TOGGLE FULL SIZE
    for button in buttons:
        if (not button.value):   # pressed?
            i = buttons.index(button)
            leds[i].value = True
           
            print("Button #%d Pressed" % i)

            # THIS SECTION MOVED UP
            # type the keycode!
            k = buttonkeys[i]    # get the corresp. keycode
            kbd.press(controlkey, k)
            kbd.release_all()

            # turn on the LED
            led.value = True
            # Wait long enough for the button to stop bouncing.
            time.sleep(0.01)
            while (not button.value):
                pass  # wait for it to be released!
 
            # turn off the LED
            led.value = False
            leds[i].value = False
   

dhalbert
 
Posts: 401
Joined: Tue Feb 17, 2015 6:18 pm

Re: Feather M0 Express!

by KyleMohr on Fri Jul 28, 2017 1:01 am

Thanks everyone for the help, moving the code down worked perfectly!

KyleMohr
 
Posts: 17
Joined: Wed Jul 29, 2015 11:49 am

Re: Feather M0 Express!

by idontneedthis on Wed Sep 06, 2017 7:47 pm

I deleted this and posted in a new topic. I was confused because this thread said Feather M0 Express and that was what I was having trouble with.
Last edited by idontneedthis on Wed Sep 06, 2017 10:43 pm, edited 1 time in total.

idontneedthis
 
Posts: 16
Joined: Mon Jun 10, 2013 3:24 pm

Re: Feather M0 Express!

by danhalbert on Wed Sep 06, 2017 7:51 pm

@idontneedthis - Please start a fresh topic with your issues.

danhalbert
 
Posts: 2139
Joined: Tue Aug 08, 2017 12:37 pm

Please be positive and constructive with your questions and comments.