mosh:element_library:switch
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| mosh:element_library:switch [2025/06/27 04:47] – mosh | mosh:element_library:switch [2025/06/27 14:22] (current) – removed mosh | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Switch ====== | ||
| - | This page describes the configuration options available for the MOSH switch element, including how to define its properties and map them to virtual wires. | ||
| - | |||
| - | The switch element reads a digital GPIO pin and reports press, release, and advanced input events such as long press, double press, and short-long combinations. | ||
| - | |||
| - | ==== Creating a Switch element ==== | ||
| - | |||
| - | <code c> | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | MOSH_Core MOSH_Core; | ||
| - | |||
| - | const uint8_t pin = 4 | ||
| - | MOSH_Element_Button* myButton = nullptr; | ||
| - | |||
| - | void setup() { | ||
| - | myButton.monitor(pin); | ||
| - | MOSH_Core.registerElement(myButton); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ==== Parameter Table: ==== | ||
| - | |||
| - | |**Option** | ||
| - | |id |integer |-- | ||
| - | |virtual_wire | ||
| - | |name |string | ||
| - | |pin | ||
| - | |active_low | ||
| - | |pullup | ||
| - | |debounce_delay | ||
| - | |press_delay | ||
| - | |long_press_delay|uint16_t|750 | ||
| - | |||
| - | ==== Property Status Messages: ==== | ||
| - | <code c> | ||
| - | enum class MOSH_Element_Button_Status | ||
| - | </ | ||
| - | |||
| - | |**Name**|**Bit**|**Description**| | ||
| - | |RESET|0x00|Reserved for future use.| | ||
| - | |STATE_ON|0x01|Sent when the button is placed in the " | ||
| - | |STATE_OFF|0x02|Sent when the button is released| | ||
| - | |PRESS|0x03|Sent when the button is pressed and released within the press_delay| | ||
| - | |DOUBLE_PRESS|0x04|Sent when the button is pressed and release twice within the press_delay| | ||
| - | |LONG_PRESS|0x05|Sent after the button is released after being pressed for long_press_delay| | ||
| - | |SHORT_LONG_PRESS|0x06|Sent after a combination of a PRESS and LONG_PRESS| | ||
| - | |USER_DEF1|0xFC|Sent with button_element.send_userdef_1()| | ||
| - | |USER_DEF2|0xFD|Sent with button_element.send_userdef_2()| | ||
| - | |USER_DEF3|0xFE|Sent with button_element.send_userdef_3()| | ||
| - | |USER_DEF4|0xFF|Sent with button_element.send_userdef_4()| | ||
| - | |||
| - | ====Static config:==== | ||
| - | None | ||
| - | |||
| - | ====Setup Methods: | ||
| - | |||
| - | Methods intended to be called during setup or initialization. These configure how the element behaves and are typically not changed during runtime. | ||
| - | |||
| - | |**Method**|**Direction**|**Required**|**Parameters**|**Description**| | ||
| - | |setActiveLow(bool)|Write|❌|bool|Button is pressed when pulled low| | ||
| - | |setDebounce(uint16_t)|Write|❌|uint16_t|Set the debounce time in milliseconds| | ||
| - | |setLongPressDelay(uint16_t)|Write|❌|uint16_t|Set the long-press delay in milliseconds| | ||
| - | |setName(string)|Write|❌|string|Set a friendly name for the element| | ||
| - | |setPin(uint8_t)|Write|✅|uint8_t|The pin the button is wired to| | ||
| - | |setPressDelay(uint16_t)|Write|❌|uint16_t|Set the press delay in milliseconds| | ||
| - | |setPullup(bool)|Write|❌|bool|Use the internal pullup| | ||
| - | |||
| - | ====Runtime Methods: ==== | ||
| - | |||
| - | |**Method**|**Direction**|**Parameters**|**returns**|**Description**| | ||
| - | |buttonIsPressed()|Read|--|bool|Returns true if button is pressed, false if not| | ||
| - | |getFriendlyName()|Read|--|string|Returns the friendly name of the element| | ||
| - | |getLastPropertyChange()|Read|--|uint32_t|get the amount of time (in millis) since the last state change)| | ||
| - | |getProperty(name)|Read|friendlyName, | ||
| - | |getID()|Read|--|uint8_t|Returns the element' | ||
| - | |getName()|Read|--|String|Returns the element' | ||
| - | |send_userdef_1()|User called|--|void|User defined action| | ||
| - | |send_userdef_2()|User called|--|void|User defined action| | ||
| - | |send_userdef_3()|User called|--|void|User defined action| | ||
| - | |send_userdef_4()|User called|--|void|User defined action| | ||
/var/www/wiki.moshnetworks.com/data/attic/mosh/element_library/switch.1750999629.txt.gz · Last modified: by mosh
