Difference between revisions of "Component: Switch Slide (Switch)"
(7 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
|- | |- | ||
| width="20%" style="color:gray;" | Author | | width="20%" style="color:gray;" | Author | ||
− | | | + | | Matrix TSL |
|- | |- | ||
| width="20%" style="color:gray;" | Version | | width="20%" style="color:gray;" | Version | ||
Line 13: | Line 13: | ||
==Switch Slide component== | ==Switch Slide component== | ||
− | A simple digital | + | A simple digital slide switch allowing latched and none latched operation. In embedded mode displays the connecting pin and pin status. |
==Component Source Code== | ==Component Source Code== | ||
+ | |||
+ | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Switch_Slide_2dgi.fcfx FC_Comp_Source_Switch_Slide_2dgi.fcfx] | ||
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Switch_Slide_2dgi.fcfx FC_Comp_Source_Switch_Slide_2dgi.fcfx] | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Switch_Slide_2dgi.fcfx FC_Comp_Source_Switch_Slide_2dgi.fcfx] | ||
==Detailed description== | ==Detailed description== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 30: | Line 38: | ||
==Examples== | ==Examples== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
Line 62: | Line 76: | ||
(5V / 11K) * 10K = 4.54545V | (5V / 11K) * 10K = 4.54545V | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | ==Macro reference== | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | ===ReadState=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 217: | Line 104: | ||
+ | ===SetState=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SetState''' |
+ | |- | ||
+ | | colspan="2" | Sets the switch to be on or off. | ||
+ | |- | ||
|- | |- | ||
− | | | + | | width="10%" align="center" | [[File:Fc9-bool-icon.png]] - BOOL |
+ | | width="90%" | State | ||
|- | |- | ||
+ | | colspan="2" | The new state of the switch (true=on, false=off) | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
Line 230: | Line 123: | ||
+ | ===WaitUntilHigh=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
− | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | ''' | + | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WaitUntilHigh''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Waits until the switch is in state 'high' The interpretation of 'high' depends on the polarity |
|- | |- | ||
− | |||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID | ||
Line 248: | Line 137: | ||
+ | ===WaitUntilLow=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 259: | Line 149: | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | |||
− | |||
Line 304: | Line 192: | ||
| colspan="2" | | | colspan="2" | | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9-type- | + | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] |
+ | | width="90%" | Component label position | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-2-icon.png]] | ||
| width="90%" | Label Colour | | width="90%" | Label Colour | ||
|- | |- | ||
Line 316: | Line 209: | ||
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | ||
| width="90%" | Show Pin Value | | width="90%" | Show Pin Value | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
+ | | width="90%" | Pin label position | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
Line 340: | Line 238: | ||
| width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-10-icon.png]] | ||
| width="90%" | Off Label | | width="90%" | Off Label | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-3-icon.png]] | ||
+ | | width="90%" | Font Type | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
|} | |} |
Latest revision as of 10:26, 20 October 2023
Author | Matrix TSL |
Version | 1.0 |
Category | Switch |
Contents
Switch Slide component
A simple digital slide switch allowing latched and none latched operation. In embedded mode displays the connecting pin and pin status.
Component Source Code
Please click here to download the component source project: FC_Comp_Source_Switch_Slide_2dgi.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_Switch_Slide_2dgi.fcfx
Detailed description
No detailed description exists yet for this component
Examples
Here is an example Flowcode program to read the value of a switch.
Switch Slide Example
Here is a schematic of how to connect a basic switch to a microcontroller pin.
The active high circuit will pass a logical 0 to the input pin when the switch is not pressed and a logical 1 when the switch is pressed.
The active low circuit will pass a logical 1 to the input pin when the switch is not pressed and a logical 0 when the switch is pressed.
There are some differences depending on the type of switch you have, the above states assume a generic push to make type switch, however a push to break type switch would have reversed logic and a toggle switch can work well with either setup.
The resistors are required for correct operation because when a microcontroller's input pin is essentially connected to nothing it will pick up noise in the environment and provide inconsistent readings. This state is referred to as floating i.e. the pin is floating. To test this remove the resistors (if possible) and touch the unconnected pin with your finger the output LED from the example file above will toggle on and off at high speed.
Any values of resistor can be used but it is important to keep the smaller resistor at least 10X smaller then the larger resistor to ensure that the pressed state provides at least 0.91% of the required pressed state voltage. For example a active high switch circuit using 1K and 10K resistors should pull up to about 4.54V when the switch is pressed.
(5V / 11K) * 10K = 4.54545V
Macro reference
ReadState
![]() |
ReadState |
Reads the button state as 0 for released or 1 for pressed Performs debounce if required | |
![]() |
Return |
SetState
![]() |
SetState |
Sets the switch to be on or off. | |
![]() |
State |
The new state of the switch (true=on, false=off) | |
![]() |
Return |
WaitUntilHigh
![]() |
WaitUntilHigh |
Waits until the switch is in state 'high' The interpretation of 'high' depends on the polarity | |
![]() |
Return |
WaitUntilLow
![]() |
WaitUntilLow |
Waits until the switch is in state 'low' The interpretation of 'high' depends on the polarity | |
![]() |
Return |