Ejemplo n.º 1
0
PORT = 4223
UID = "XYZ"  # Change XYZ to the UID of your Analog In Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_analog_in import BrickletAnalogIn


# Callback function for voltage reached callback (parameter has unit mV)
def cb_voltage_reached(voltage):
    print("Voltage: " + str(voltage / 1000.0) + " V")


if __name__ == "__main__":
    ipcon = IPConnection()  # Create IP connection
    ai = BrickletAnalogIn(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 10 seconds (10000ms)
    ai.set_debounce_period(10000)

    # Register voltage reached callback to function cb_voltage_reached
    ai.register_callback(ai.CALLBACK_VOLTAGE_REACHED, cb_voltage_reached)

    # Configure threshold for voltage "smaller than 5 V" (unit is mV)
    ai.set_voltage_callback_threshold("<", 5 * 1000, 0)

    raw_input("Press key to exit\n")  # Use input() in Python 3
    ipcon.disconnect()
HOST = "localhost"
PORT = 4223
UID = "XYZ" # Change XYZ to the UID of your Analog In Bricklet

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_analog_in import BrickletAnalogIn

# Callback function for voltage reached callback
def cb_voltage_reached(voltage):
    print("Voltage: " + str(voltage/1000.0) + " V")

if __name__ == "__main__":
    ipcon = IPConnection() # Create IP connection
    ai = BrickletAnalogIn(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 10 seconds (10000ms)
    ai.set_debounce_period(10000)

    # Register voltage reached callback to function cb_voltage_reached
    ai.register_callback(ai.CALLBACK_VOLTAGE_REACHED, cb_voltage_reached)

    # Configure threshold for voltage "smaller than 5 V"
    ai.set_voltage_callback_threshold("<", 5*1000, 0)

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

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

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_analog_in import BrickletAnalogIn

# Callback function for voltage callback (parameter has unit mV)
def cb_voltage(voltage):
    print("Voltage: " + str(voltage/1000.0) + " V")

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

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

    # Register voltage callback to function cb_voltage
    ai.register_callback(ai.CALLBACK_VOLTAGE, cb_voltage)

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

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