Jump to content

[Python] Programm beenden


Recommended Posts

Hallo,

 

ich versuche ein Programm zu schreiben, dass beendet wird sobald von einem TF Aktuator ein Event eintritt. Im Moment nutze ich den Threshold von einem Poti dafür.

 

Es klappt auch soweit, nur bleibt in der Konsole der raw_input stehen. Wie kann man das umgehen? Ich habe es mit einer while-Schleife probiert aber ich bekomme den Wert des Thresholds nicht in die Schleife.

 

Wäre für Tipps sehr dankbar.

 

Hier mein Code:

 

HOST = "localhost"
PORT = 4223
UID_TEMP = 'zv2'
UID_OLED = 'Bgv'
UID_ROTA = 'g5H'

stop = 0.0

from tinkerforge.ip_connection import IPConnection
from tinkerforge.bricklet_temperature import BrickletTemperature
from tinkerforge.bricklet_rotary_poti import BrickletRotaryPoti
from tinkerforge.bricklet_oled_128x64 import BrickletOLED128x64

import sys

def cb_temperature(temperature):
    oled.write_line(0, 0, 'Temperature: ' + str(temperature/100.0) + ' C')
    
def cb_position(position):
    oled.clear_display()
    ipcon.disconnect()
    
if __name__ == "__main__":
    
    ipcon = IPConnection()
    
    t = BrickletTemperature(UID_TEMP, ipcon)
    rp = BrickletRotaryPoti(UID_ROTA, ipcon)
    oled = BrickletOLED128x64(UID_OLED, ipcon)

    ipcon.connect(HOST, PORT)

    t.register_callback(t.CALLBACK_TEMPERATURE, cb_temperature)
    t.set_temperature_callback_period(1000)
    
    rp.register_callback(rp.CALLBACK_ANALOG_VALUE_REACHED, cb_position)
    rp.set_debounce_period(100)
    rp.set_analog_value_callback_threshold('>', 3000.0, 4095)  
    
    raw_input("Press key to exit\n")

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...