Jump to content

DualButton Led will nicht


Recommended Posts

Hallo zusammen,

ich habe folgendes Problem:

Ich habe einen DualButton und möchte Testweise die linke LED mit Python einschalten.

Ich habe das Beispielprogramm genommen und erweitert, aber es will nicht so wie ich will.

 

HOST = "localhost"
PORT = 4223
UID_dualButton = "MeA"                                                           # Change XYZ to the UID of your Dual Button Bricklet 2.0

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_dual_button_v2 import BrickletDualButtonV2

def cb_state_changed(dualbutton_l, dualbutton_r, led_l, led_r):              # Callback function for state changed callback
    if dualbutton_l == BrickletDualButtonV2.BUTTON_STATE_PRESSED:
        print("Linker Button: gedrückt")
    elif dualbutton_l == BrickletDualButtonV2.BUTTON_STATE_RELEASED:
        print("Linker Button: nicht gedrückt")

    if dualbutton_r == BrickletDualButtonV2.BUTTON_STATE_PRESSED:
        print("Rechter Button: gedrückt")
    elif dualbutton_r == BrickletDualButtonV2.BUTTON_STATE_RELEASED:
        print("Rechter Button: nicht gedrückt")
    print("")

if __name__ == "__main__":
    ipcon = IPConnection()                                                          # Create IP connection
    db = BrickletDualButtonV2(UID_dualButton, ipcon)                        # Create device object

    ipcon.connect(HOST, PORT)                                                   # Connect to brickd
    # Don't use device before ipcon is connected

 

#------------------------------

 Dies sind meine Versuche
    #db.setLEDState(BrickletDualButton.LED_STATE_ON, BrickletDualButton.LED_STATE_OFF)
    # db.set_selected_led_state(BrickletDualButtonV2.LED_STATE_OFF, BrickletDualButtonV2.LED_STATE_ON)
    #db.BrickletDualButtonV2.set_selected_led_state(0, 2)
    #print(BrickletDualButtonV2.get_led_state())
    # BrickletDualButtonV2.set_selected_led_state(0, 2)
    # BrickletDualButtonV2.set_led_state(2, 2)

#-----------------------------

 

    # Register state changed callback to function cb_state_changed
    db.register_callback(db.CALLBACK_STATE_CHANGED, cb_state_changed)
    db.set_state_changed_callback_configuration(True)                       # Enable state changed callback

    input("Press key to exit\n")
    ipcon.disconnect()
 

Wo ist da der Fehler?

 

Vielen Dank im Voraus.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...