User Tools

Site Tools


mosh:element_library:button

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
mosh:element_library:button [2025/06/27 04:16] – [Button] moshmosh:element_library:button [2025/06/30 15:38] (current) – [Runtime Methods:] mosh
Line 8: Line 8:
  
 <code c> <code c>
 +#include <mosh_core.h>
 +#include <elements/button.h>
 +
 +MOSH_Core MOSH_Core;
 +
 const uint8_t pin = 4 const uint8_t pin = 4
 MOSH_Element_Button* myButton = nullptr; MOSH_Element_Button* myButton = nullptr;
 +
 void setup() { void setup() {
   myButton.monitor(pin);   myButton.monitor(pin);
 +  MOSH_Core.registerElement(myButton);
 } }
- 
 </code> </code>
  
 ==== Parameter Table: ==== ==== Parameter Table: ====
  
-|**Option**      |**Type**|**Default**|**Description**| +|**Option**          |**Type**|**Default**|**Description**
-|id              |integer |--   |Unique Element ID| +|active_low          |bool    |false|Whether active state is low (true for inverted logic)| 
-|virtual_wire    |uint8_t |--   |ID(s) of the virtual wire(sassigned+|debounce_delay      |uint8_t |50   |Amount of delay (in milliseconds) used for debouncing
-|name            |string  |--   |Friendly label| +|id                  |integer |--   |Unique Element ID| 
-|pin             |uint8_t |--   |GPIO pin number connected to the button| +|long_press_delay    |uint16_t|750  |Amount of delay (in millisecondsfor determining a long press
-|active_low      |bool    |false|Whether active state is low (true for inverted logic)| +|name                |string  |--   |Friendly label| 
-|pullup          |bool    |true |Enable internal pull-up resistor| +|pin                 |uint8_t |--   |GPIO pin number connected to the button| 
-|debounce_delay  |uint8_t |50   |Amount of delay (in milliseconds) used for debouncing.+|press_delay         |uint16_t|250  |Amount of delay (in millisecondsfor determining a short press
-|press_delay     |uint16_t|250  |Amount of delay (in milliseconds) for determining long vs. short press.+|pullup              |bool    |true |Enable internal pull-up resistor| 
-|long_press_delay|uint16_t|750  |Amount of delay (in milliseconds) for determining a long press.+|stream_on_press     |bool    |false|Sends a stream of PRESS notifications when the button is active
 +|stream_on_press_freq|uint16_t|50   |The amount of time between PRESS notifications when stream_on_press is true
 +|virtual_wire        |uint8_t |--   |ID of the virtual wire is assigned
 +|constant_on         |bool    |false|When 
 ==== Property Status Messages: ==== ==== Property Status Messages: ====
 <code c> <code c>
Line 35: Line 43:
  
 |**Name**|**Bit**|**Description**| |**Name**|**Bit**|**Description**|
-|RESET|0x00|Sent when the switch is first registered.|+|RESET|0x00|Reserved for future use.|
 |STATE_ON|0x01|Sent when the button is placed in the "pressed" position.| |STATE_ON|0x01|Sent when the button is placed in the "pressed" position.|
 |STATE_OFF|0x02|Sent when the button is released| |STATE_OFF|0x02|Sent when the button is released|
Line 54: Line 62:
 Methods intended to be called during setup or initialization. These configure how the element behaves and are typically not changed during runtime. 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**+|**Method**|**Direction**|**Required**|**Default**|**Parameters**|**Description**| 
-|onPropertyChange(callback)|Subscribe|❌|callback(property, value)|Callback for when the state property changes.| +|setActiveLow(bool)|Write|❌|true|bool|Button is pressed when pulled low| 
-|onPriority(callback)|Subscribe|❌|callback(property, value)|Similar to `onPropertyChange`, but triggers immediately for high-priority events like button presses, which may affect timing-sensitive behavior.+|setDebounce(uint16_t)|Write|❌|10|uint16_t|Set the debounce time in milliseconds| 
-|setActiveLow(bool)|Write|❌|bool|Button is pressed when pulled low| +|setLongPressDelay(uint16_t)|Write|❌|750|uint16_t|Set the long-press delay in milliseconds| 
-|setDebounce(uint16_t)|Write|❌|uint16_t|Set the debounce time in milliseconds| +|setName(string)|Write|❌|//null//|string|Set a friendly name for the element| 
-|setLongPressDelay(uint16_t)|Write|❌|uint16_t|Set the long-press delay in milliseconds| +|setPin(uint8_t)|Write|✅|//null//|uint8_t|The pin the button is wired to| 
-|setName(string)|Write|❌|string|Set a friendly name for the element| +|setPressDelay(uint16_t)|Write|❌|250|uint16_t|Set the press delay in milliseconds| 
-|setPin(uint8_t)|Write|✅|uint8_t|The pin the button is wired to| +|setPullup(bool)|Write|❌|true|bool|Use the internal pullup| 
-|setPressDelay(uint16_t)|Write|❌|uint16_t|Set the press delay in milliseconds| +|setStreamOnPress(bool)|Write|❌|false|bool|Button will send stream of PRESS events while active| 
-|setPullup(bool)|Write|❌|bool|Use the internal pullup| +|setStreamOnPressFreq(uint16_t)|Write|❌|//null//|uint16_t|Sets how frequently a PRESS event is sent during a press stream|
 ====Runtime Methods: ==== ====Runtime Methods: ====
  
Line 70: Line 77:
 |buttonIsPressed()|Read|--|bool|Returns true if button is pressed, false if not| |buttonIsPressed()|Read|--|bool|Returns true if button is pressed, false if not|
 |getFriendlyName()|Read|--|string|Returns the friendly name of the element| |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)|+|getLastPropertyChange()|Read|--|uint32_t|get the amount of time (in millies) since the last state change)|
 |getProperty(name)|Read|friendlyName, state, event, lastChange|PropertyValue|Returns the current value of a property| |getProperty(name)|Read|friendlyName, state, event, lastChange|PropertyValue|Returns the current value of a property|
 |getID()|Read|--|uint8_t|Returns the element's unique ID| |getID()|Read|--|uint8_t|Returns the element's unique ID|
/var/www/wiki.moshnetworks.com/data/attic/mosh/element_library/button.1750997800.txt.gz · Last modified: by mosh

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki