Nov-29-2017, 05:50 PM
(Nov-29-2017, 05:40 PM)DeaD_EyE Wrote: What you want to use is something like a Schmitt trigger. You can do this as a class because you need the last state. Using global variables is not good.
Here an example:
import time class SchmittTrigger: def __init__(self, low_val, high_val): self.state = False self.low_val = low_val self.high_val = high_val def update(self, value): if value < self.low_val: self.state = True elif value > self.high_val: self.state = False # when the value is between low and high # the last state is unchanged return self.state temperatures = [15, 20, 26, 28, 29, 30, 31, 32, 33, 30, 30, 29, 28, 27, 26, 25] schmitt_trigger = SchmittTrigger(28, 31) text = 'Temperature at {} °C heater is {}.' for temp in temperatures: time.sleep(1) print(text.format(temp, 'on' if schmitt_trigger.update(temp) else 'off'))
sounds good, sadly im a pretty newb in python...
could you give me a few more details on how i could form that into a fitting code for my needings :D