Relay module

🛠️ 1.1.3
This topic is closed (tagged ).
12 days ago

New module - RELAY.

2 inputs - Enable, ValueIN
1 output - ValueOUT

Acts like a real life relay, when enable = 1, passes value from connected input 2 to output 1. When enable = 0, immediatly resets output to default = 0 or other defined value in module settings.

from Core.categories import DefaultCategories
from Core.fields import Int32Field
from Core.io import Input, Output, Display
from Core.mafi import fix
from Mafi import Fix32
from Core.module import DefaultControllers, Module, ModuleStatus


class Runtime_Relay(Module):
    name = "Control: Relay"
    description = "When <b>enable</b> is 1, passes connected <b>value</b> input to output; when <b>enable</b> is 0, outputs the <b>default</b> field value."
    symbol = "RLY"

    inputs = [
        Input("enable", "Enable"),
        Input("passed_value", "State when enabled")
    ]

    outputs = [
        Output("output", "Output")
    ]

    fields = [
        Int32Field("default", "Default (when disabled)", "Output this when enable=0", 0)
    ]

    displays = [
        Display.Filler(fix(1)),
        Display.LED("active", "Relay Active")
    ]

    width = 2

    categories = [ DefaultCategories.Control ]
    controllers = [ DefaultControllers.Controller ]

    def action(self):
        enable = self.Input.get_bool("enable", False)
        
        if enable:
            # When enable is 1, pass passed_value input
            output = self.Input.get("passed_value", Fix32.Zero)
        else:
            # When enable is 0, use default field
            output = self.Field.get("default", Fix32.Zero)
        
        self.Output.set("output", output)
        return ModuleStatus.Running

    def Display(self):
        # show LED when enabled
        if self.Input.get_bool("enable", False):
            self.Display.set("active", "on")
        else:
            self.Display.set("active", "")
5 days ago

Hi, I would implement this module in next version, may happen, that after update, the pins passed_value and output will lose connection on load.

22 Showing 12 of 2
Log in to reply.