Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


GPIO buttons that fire on connect.
#1
I would like to use a rotary switch to select playlists on one of my moOde players.  I've got scripts mapped to the GPIO button handler that load and play the playlists as I need, but because the script attached to the button fires when the button disconnects my rotary switch will play the playlist attached to the position it just left, not the one for the position it is in.
Is there a way to get the buttons to run the attached scripts when the contact is made, rather than when the contact is broken?

Is it as simple as:

Code:
GPIO.add_event_detect(sw_1_pin, GPIO.RISING, callback=sw_1_event, bouncetime=bounce_time)
becoming

Code:
GPIO.add_event_detect(sw_1_pin, GPIO.FALLING, callback=sw_1_event, bouncetime=bounce_time)
in the gpio-buttons.py
----------------
Robert
Reply
#2
@the_bertrum

Real hackers don't ask for directions. They hack first and brag (or complain) after Smile 

I expect the sense of the transition you want to trigger on depends on how you've wired your switch to the GPIO. Experimentation is par for the course and what you suggest seems reasonable. 

Rotary switches are generally "noisy" so it's possible you have to deal with switch bounce as well.

Regards,
Kent
Reply
#3
Cry
But I'm all nervous Kent, I don't want to break my system!

But I did go a-hacking anyway and find that:

Code:
           if GPIO.input(channel) == 0:
rather than:

Code:
           if GPIO.input(channel) == 1:
in the gpio-buttons.py file has the desired effect.

Now to work out how that works because my current understanding suggests it shouldn't be enough on its own.
----------------
Robert
Reply
#4
IIRC in the code the var channel is the GPIO PIN number and GPIO.input(channel) can return either 0 or 1 (false / true) where 0 = pin level is LOW, 1 = pin level is HIGH.
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply


Forum Jump: