Class ToggleSwitch - GSTCH/SketchMadeEASY GitHub Wiki

Input ToggleSwitch

Topic Specification
Description The value toggles between 0 and 1. The value changes when one of the pins goes to high. PinDirection1 set value to 0, PinDirection2 set value to 1. Use this class e.g. to toggle a motor between to limit switches.
Optional is a debounce time (duration to ignore any changes after LOW/HIGH or HIGH/LOW change).
This classes support the SwitchResistoreMode, set in the constructor. Default is internal pullup.
Constructor ToggleSwitch::ToggleSwitch (int PinDirection1, int PinDirection2, ESwitchResistoreMode SwitchResistoreMode, int DebounceTimeMSec)
Parameter
PinDirection1: Digital pin. When pin value changes to high, the class value set to 0
PinDirection2: Digital pin. When pin value changes to high, the class value set to 1
SwitchResistoreMode: Optional with default smPullDownInternal (0). Details read SwitchResistoreMode. Possible values are:
  • smPullDownInternal (=0)
  • smPullDownExternal (=1)
  • smPullUpExternal (=2)
    Sketch Made Easy hides the different values of the pin and always has the same value
    DebounceTimeMSec: Optional with Default=50ms. The interval that must pass before a value changed is accepted. Value in Milliseconds.
  • Range 0…1
    Const 0: ToggleSwitch::Pos1
    1: ToggleSwitch::Pos2
    Samples ToggleSwitch toggleSwitch = new ToggleSwitch(5, 6);
    ToggleSwitch toggleSwitch = new ToggleSwitch(5, 6, smPullDownExternal);
    ToggleSwitch toggleSwitch = new ToggleSwitch(5, 6, smPullUpExternal, 60);
    Examples Example 08‐Motor toggles between Limit‐Switches
    Example 09‐Motor toggles between limit switches, main switch
    Example 10‐Main Motor turns between limit switches, second follows
    ⚠️ **GitHub.com Fallback** ⚠️