Python Forum
Relay switches On and Off every cylcle...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Relay switches On and Off every cylcle...
#7
(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
Reply


Messages In This Thread
RE: Relay switches On and Off every cylcle... - by hotwalk - Nov-29-2017, 05:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert looping home security to a one time scan of switches and sensors duckredbeard 0 1,723 Dec-08-2020, 04:31 AM
Last Post: duckredbeard
  Problem connecting to 2 switches, HELP! Netcode 0 1,196 Nov-15-2019, 10:30 PM
Last Post: Netcode

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020