コード例 #1
0
HOST = "localhost"
PORT = 4223
UID = "XYZ"  # Change XYZ to the UID of your Line Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_line import BrickletLine

# Callback function for reflectivity reached callback
def cb_reflectivity_reached(reflectivity):
    print("Reflectivity: " + str(reflectivity))


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    l = BrickletLine(UID, ipcon)  # Create device object

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

    # Get threshold callbacks with a debounce time of 1 second (1000ms)
    l.set_debounce_period(1000)

    # Register reflectivity reached callback to function cb_reflectivity_reached
    l.register_callback(l.CALLBACK_REFLECTIVITY_REACHED, cb_reflectivity_reached)

    # Configure threshold for reflectivity "greater than 2000"
    l.set_reflectivity_callback_threshold(">", 2000, 0)

    raw_input("Press key to exit\n")  # Use input() in Python 3
    ipcon.disconnect()
コード例 #2
0
HOST = "localhost"
PORT = 4223
UID = "XYZ"  # Change XYZ to the UID of your Line Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_line import BrickletLine


# Callback function for reflectivity reached callback
def cb_reflectivity_reached(reflectivity):
    print("Reflectivity: " + str(reflectivity))


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    l = BrickletLine(UID, ipcon)  # Create device object

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

    # Get threshold callbacks with a debounce time of 1 second (1000ms)
    l.set_debounce_period(1000)

    # Register reflectivity reached callback to function cb_reflectivity_reached
    l.register_callback(l.CALLBACK_REFLECTIVITY_REACHED,
                        cb_reflectivity_reached)

    # Configure threshold for reflectivity "greater than 2000"
    l.set_reflectivity_callback_threshold(">", 2000, 0)

    input("Press key to exit\n")  # Use raw_input() in Python 2
コード例 #3
0
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Line Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_line import BrickletLine

# Callback function for reflectivity callback
def cb_reflectivity(reflectivity):
    print("Reflectivity: " + str(reflectivity))

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    l = BrickletLine(UID, ipcon) # Create device object

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

    # Register reflectivity callback to function cb_reflectivity
    l.register_callback(l.CALLBACK_REFLECTIVITY, cb_reflectivity)

    # Set period for reflectivity callback to 1s (1000ms)
    # Note: The reflectivity callback is only called every second
    #       if the reflectivity has changed since the last call!
    l.set_reflectivity_callback_period(1000)

    raw_input("Press key to exit\n") # Use input() in Python 3
    ipcon.disconnect()
コード例 #4
0
HOST = "localhost"
PORT = 4223
UID = "XYZ"  # Change XYZ to the UID of your Line Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_line import BrickletLine


# Callback function for reflectivity callback
def cb_reflectivity(reflectivity):
    print("Reflectivity: " + str(reflectivity))


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    l = BrickletLine(UID, ipcon)  # Create device object

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

    # Register reflectivity callback to function cb_reflectivity
    l.register_callback(l.CALLBACK_REFLECTIVITY, cb_reflectivity)

    # Set period for reflectivity callback to 1s (1000ms)
    # Note: The reflectivity callback is only called every second
    #       if the reflectivity has changed since the last call!
    l.set_reflectivity_callback_period(1000)

    input("Press key to exit\n")  # Use raw_input() in Python 2
    ipcon.disconnect()
コード例 #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Line Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_line import BrickletLine

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    l = BrickletLine(UID, ipcon) # Create device object

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

    # Get current reflectivity
    reflectivity = l.get_reflectivity()
    print("Reflectivity: " + str(reflectivity))

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