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

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_linear_poti import BrickletLinearPoti

# Callback function for position callback (parameter has range 0 to 100)
def cb_position(position):
    print("Position: " + str(position))


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

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

    # Register position callback to function cb_position
    lp.register_callback(lp.CALLBACK_POSITION, cb_position)

    # Set period for position callback to 0.05s (50ms)
    # Note: The position callback is only called every 0.05 seconds
    #       if the position has changed since the last call!
    lp.set_position_callback_period(50)

    raw_input("Press key to exit\n")  # Use input() in Python 3
    ipcon.disconnect()
# -*- coding: utf-8 -*-

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

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_linear_poti import BrickletLinearPoti

# Callback function for position callback (parameter has range 0 to 100)
def cb_position(position):
    print("Position: " + str(position))

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

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

    # Register position callback to function cb_position
    lp.register_callback(lp.CALLBACK_POSITION, cb_position)

    # Set period for position callback to 0.05s (50ms)
    # Note: The position callback is only called every 0.05 seconds
    #       if the position has changed since the last call!
    lp.set_position_callback_period(50)

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

    time.sleep(1)

    o_clear()
    print("Callbacks werden registriert")
    o_write(1, 5, "Callbacks")
    o_write(1, 3, "werden registriert")

    dcb.register_callback(dcb.CALLBACK_VELOCITY_REACHED,
                          lambda x: cb_dcb_velocity(x, dcb))
    stepper.register_callback(BrickStepper.CALLBACK_UNDER_VOLTAGE,
                              cb_stepper_undervoltage)
    ropoti.register_callback(BrickletRotaryPoti.CALLBACK_POSITION,
                             cb_rotary_fancontrol)
    poti.register_callback(BrickletLinearPoti.CALLBACK_POSITION,
                           cb_linearpoti_controller)
    irsensor.register_callback(BrickletDistanceIR.CALLBACK_DISTANCE,
                               cb_irsensor_distance)

    o_clear()
    print("Bricks werden gestartet")
    o_write(1, 6, "Bricks")
    o_write(1, 3, "werden aktiviert")

    stepper.enable()
    dcb.enable()

    time.sleep(1)

    ctrl_status = "Angeschaltet"
    updt_oled()