ich habe an meinem TXT 4.0 eine Lichtschranken-LED (O7) und einen Fototransistor (I4) angeschlossen. Die controller.py sieht wie folgt aus:
Code: Alles auswählen
import fischertechnik.factories as txt_factory
txt_factory.init()
txt_factory.init_input_factory()
txt_factory.init_output_factory()
TXT_M = txt_factory.controller_factory.create_graphical_controller()
TXT_M_I4_photo_transistor = txt_factory.input_factory.create_photo_transistor(TXT_M, 4)
TXT_M_O7_led = txt_factory.output_factory.create_led(TXT_M, 7)
txt_factory.initialized()
Code: Alles auswählen
from time import sleep, time
from lib.controller import *
def callback2(event):
start = time()
while TXT_M_I4_photo_transistor.is_bright():
sleep(0.001)
end = time()
print("duration %f" % (end - start))
TXT_M_I4_photo_transistor.add_change_listener("bright", callback2)
TXT_M_O7_led.set_brightness(0)
TXT_M_O7_led.set_brightness(512)
sleep(1)
TXT_M_O7_led.set_brightness(0)
sleep(1)
TXT_M_O7_led.set_brightness(512)
sleep(1)
TXT_M_O7_led.set_brightness(0)
sleep(0.1)
Code: Alles auswählen
Program starts ...
duration 0.993381
duration 0.000035
duration 0.993475
duration 0.000031
Program finished.
Gruß
haferfleks