Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Geschrieben

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()

 

Geschrieben
  • Autor

Das ist ein Beispielscript von Tinkerforge. Ich selber kenn mich nur mit C/C++ aus. :-X

Geschrieben

Richtig. Und das Beispielscript muss angepasst werden um Deine Anfangsfrage zu beantworten.

 

Der Loetkolben

Geschrieben

Den Brick-Viewer starten, jeder angeschlossene Brick und Bricklet-Baustein wird dann aufgelistet. Die UID ablesen und in das Beispiel-Script (egal welcher Programmiersprache) statt dem Platzhalter XYZ eintragen.

Die Beispiele in C/C++:

http://www.tinkerforge.com/doc/Software/Bricklets/DistanceIR_Bricklet_C.html#distance-ir-bricklet-c

Join the conversation

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

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.