Jump to content

[Python] Wie soll ich Phyton sagen, dass es sich mit dem Brick verbinden soll?


Recommended Posts

Hallo,

Meine Frage:Wie soll ich Phyton sagen, dass es sich mit dem Brick verbinden soll?

Wie verbindet sich Phyton mit den Bricks? Wenn ich direkt den Quellcode eingebe sagt es, es könne nicht das angegebene Modul finden.

Quelltext:

 

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change to your UID

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_distance_ir import DistanceIR

# Callback function for distance callback (parameter has unit mm)
def cb_distance(distance):
    print('Distance: ' + str(distance/10.0) + ' cm')

if __name__ == "__main__":
    ipcon = IPConnection(HOST, PORT) # Create IP connection to brickd

    dist = DistanceIR(UID) # Create device object
    ipcon.add_device(dist) # Add device to IP connection
    # Don't use device before it is added to a connection

    # Set Period for distance callback to 0.2s (200ms)
    # Note: The callback is only called every 200ms if the 
    #       distance has changed since the last call!
    dist.set_distance_callback_period(200)

    # Register distance callback to function cb_distance
    dist.register_callback(dist.CALLBACK_DISTANCE, cb_distance)

    raw_input('Press key to exit\n') # Use input() in Python 3
    ipcon.destroy()

 

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.

 Share

×
×
  • Create New...