Ist es vielleicht auch möglich, dass ich dem Programm sage, Gib mir nur dann eine Ausgabe, falls du Signale von Channel 1 kriegst.
Bisher habe ich selbst definiert, dass mein Channel_number=1 ist (siehe oben). Jedoch ist nun der Schritt, dass auch ein Signal B gegeben wird.
Ich habe es mit diesem Schritt versucht, aber irgendwie funktioniert es nicht so ganz:
def channel_number (channel):
if channel == BrickletIndustrialDigitalIn4V2.CHANNEL_0:
# Configure rising edge count (channel 3) with 10ms debounce
idi4.set_edge_count_configuration(channel=0, edge_type=1, debounce=1)
elif channel == BrickletIndustrialDigitalIn4V2.CHANNEL_1:
print('Falsche Richtung')
leider kriege ich aber keine Werte so rausgespuckt..
Hier nochmal der ganze Skript:
HOST = "localhost"
PORT = 4223
UID = "PN5" # Change XYZ to the UID of your Industrial Digital In 4 Bricklet 2.0
import math
import time
from tinkerforge.bricklet_industrial_digital_in_4_v2 import BrickletIndustrialDigitalIn4V2
from tinkerforge.ip_connection import IPConnection
def channel_number (channel):
global count
if channel == BrickletIndustrialDigitalIn4V2.CHANNEL_0:
# Configure rising edge count (channel 0) with 10ms debounce
idi4.set_edge_count_configuration(channel=0, edge_type=1, debounce=1)
count = idi4.get_edge_count(channel=0, reset_counter=False)
elif channel == BrickletIndustrialDigitalIn4V2.CHANNEL_1:
print('Falsche Richtung')
if __name__ == "__main__":
ipcon = IPConnection() # Create IP connection
idi4 = BrickletIndustrialDigitalIn4V2(UID, ipcon) # Create device object
ipcon.connect(HOST, PORT) # Connect to brick
b = 0.0
endTime = time.time() + 60*60*8
print(time.ctime() + "\tStart Logging..")
print("-----------------------------------------------------")
while time.time() < endTime:
time.sleep(1)
r = 0.03 # meter
alpha = (count * 360) / 1024 # P = Anzahl Impulse, PPR = Impulse pro Umdrehung = 1024
d = b
b = (alpha / 360) * 2 * math.pi * r
# - b_old
if b > 0.0 and b != d:
print(time.ctime() + "\t" + str(b))
print("-----------------------------------------------------")
print(time.ctime() + "\tEnd of the Log")
# input("Press key to exit\n") # Use raw_input() in Python 2
ipcon.disconnect()