#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Rotary Poti Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_rotary_poti import BrickletRotaryPoti if __name__ == "__main__": ipcon = IPConnection() # Create IP connection rp = BrickletRotaryPoti(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get current position position = rp.get_position() print("Position: " + str(position)) # Range: -150 to 150 raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
# Configure Servo so that it rotates 180° servo.set_pulse_width(6, 650, 2350) servo.enable(6) # Clear display oled.clear_display() # Draw text once at beginning, the window in draw_matrix does not overwrite # the last line of the display oled.write_line(7, 5, "tinkerforge.com") # We just use an endless loop here, press ctrl + c to abort the script while True: # With position 110 poti is at 90° angle = poti.get_position() * 90 // 110 if angle > 90: angle = 90 elif angle < -90: angle = -90 # Set servo position according to angle servo.set_position(6, angle * 100) # Create angle text angle_str = str(angle) + u'°' if angle >= 0: angle_str = ' ' + angle_str # Draw servo position line img = Image.new('1', (128, 64), 0)
#!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 UID = "XYZ" # Change XYZ to the UID of your Rotary Poti Bricklet from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_rotary_poti import BrickletRotaryPoti if __name__ == "__main__": ipcon = IPConnection() # Create IP connection rp = BrickletRotaryPoti(UID, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before ipcon is connected # Get current position (range is -150 to 150) position = rp.get_position() print("Position: " + str(position)) raw_input("Press key to exit\n") # Use input() in Python 3 ipcon.disconnect()
# Configure Servo so that it rotates 180° servo.set_pulse_width(6, 650, 2350) servo.enable(6) # Clear display oled.clear_display() # Draw text once at beginning, the window in draw_matrix does not overwrite # the last line of the display oled.write_line(7, 5, "tinkerforge.com") # We just use an endless loop here, press ctrl + c to abort the script while True: # With position 110 poti is at 90° angle = poti.get_position()*90//110 if angle > 90: angle = 90 elif angle < -90: angle = -90 # Set servo position according to angle servo.set_position(6, angle*100) # Create angle text angle_str = str(angle) + u'°' if angle >= 0: angle_str = ' ' + angle_str # Draw servo position line img = Image.new('1', (128, 64), 0)