Headlights
Forums:
Hello, is it possible to use a button on the ps3 controller to switching led on and off? For example with the L1 button
Greetings Thieu
- Log in to post comments

Hello, is it possible to use a button on the ps3 controller to switching led on and off? For example with the L1 button
Greetings Thieu
piborg
Tue, 03/12/2019 - 22:03
Permalink
Setting an LED on a button press
It is fairly simple to add a new button :)
First add the button's number to the "settings" section towards the top of the script:
There is a quick reference sheet here for PS3 remotes, otherwise you can use
jstest /dev/input/js0
and see which value changes when you press the button you wantSecond look for the
elif event.type == pygame.JOYBUTTONDOWN:
line and add a test for the event button code inside that block like this:If everything has worked you should see the printed message each time you press the button you have set.
All you then need to do is swap the print statement for the code to change your LED.
Thieu
Tue, 06/30/2020 - 18:57
Permalink
Hello piborg, is it possible
Hello piborg, is it possible to set the light on when button hold
And light off when button not hold?
Greetings Thieu
piborg
Wed, 07/01/2020 - 16:03
Permalink
Yes it is :)
What you need is the ability to detect when the button is pressed and when it is released.
The
pygame.JOYBUTTONDOWN
event happens when a button is pressed, so the same change from before can be used to turn the light on.The
pygame.JOYBUTTONUP
event happens when a button is released. We can add another event type to detect this and use it to turn the light off.This code should print the correct messages as the button is pressed and released. All you then need is the code to turn the light on and off :)
Thieu
Wed, 07/01/2020 - 18:38
Permalink
Many thanks piborg👍
Many thanks piborg👍