Difference between revisions of "Component: Switch Push Button (Switch)"
(Created page with "{| style="width:50%" |- | width="20%" style="color:gray;" | Author | Matrix TSL |- | width="20%" style="color:gray;" | Version | 1.0 |- | width="20%" style="color:gray...") |
|||
(14 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
|- | |- | ||
| width="20%" style="color:gray;" | Version | | width="20%" style="color:gray;" | Version | ||
− | | | + | | 15.0 |
|- | |- | ||
| width="20%" style="color:gray;" | Category | | width="20%" style="color:gray;" | Category | ||
Line 15: | Line 15: | ||
A simple digital push switch allowing latched and none latched operation. In embedded mode displays the connecting pin and pin status. | A simple digital push switch allowing latched and none latched operation. In embedded mode displays the connecting pin and pin status. | ||
− | == | + | ==Version information== |
− | + | Library Version, Component Version, Date, Author, Info | |
+ | 15, 15.0, 30-07-24, MW, Fixed a bug to make sure switch starts in the off position | ||
+ | 15, 15.0, 18-08-24, MW, Added option for simulation only | ||
+ | 15, 15.0, 30-07-24, MW, Fixed a bug preventing custom lable posistion from updating on the fly | ||
==Detailed description== | ==Detailed description== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
''No detailed description exists yet for this component'' | ''No detailed description exists yet for this component'' | ||
Line 25: | Line 40: | ||
==Examples== | ==Examples== | ||
− | |||
− | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | Here is an example Flowcode program to read the value of a switch. | ||
+ | {{Fcfile|Switch.fcfx|Switch}} | ||
+ | |||
+ | Here is a schematic of how to connect a basic switch to a microcontroller pin. | ||
+ | |||
+ | [[File:switchschematic.jpg]] | ||
+ | |||
+ | 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 | ||
+ | |||
+ | Note: if you want to use switch functions e.g. Active Low or debounce ,you must use the ReadState function and not use just an input. | ||
+ | |||
+ | ==Macro reference== | ||
+ | |||
+ | ===ReadState=== | ||
{| 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;" | '''ReadState''' |
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Reads the button state as 0 for released or 1 for pressed Performs debounce if required |
|- | |- | ||
|- | |- | ||
− | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9- | + | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE |
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
+ | ===SetState=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 60: | Line 112: | ||
+ | ===WaitUntilHigh=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''WaitUntilHigh''' | ||
+ | |- | ||
+ | | 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="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | ===WaitUntilLow=== | ||
{| class="wikitable" style="width:60%; background-color:#FFFFFF;" | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
|- | |- | ||
Line 71: | Line 138: | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
− | |||
− | |||
Line 82: | Line 147: | ||
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties''' | ||
|- | |- | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Function | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | ||
+ | | width="90%" | Simulation Only | ||
+ | |- | ||
+ | | colspan="2" | | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
Line 90: | Line 164: | ||
| width="90%" | Connection | | width="90%" | Connection | ||
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | The chip pin to which the switch connects. |
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
| width="90%" | Polarity | | width="90%" | Polarity | ||
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Set the polarity of states sent to the chip pin. 'Active High' -> Pressed = Set, Released = Clear 'Active Low' -> Pressed = Clear, Released = Set |
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
| width="90%" | Debounce | | width="90%" | Debounce | ||
|- | |- | ||
− | | colspan="2" | | + | | colspan="2" | Sets the time in milliseconds to allow a pin change to settle into a stable state. NB) Debouncing is only used when reading the button state using the component macros. Chip pins are NOT debounced. |
|- | |- | ||
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | ||
| width="90%" | Latching | | width="90%" | Latching | ||
+ | |- | ||
+ | | colspan="2" | Determines if the simulated switch maintains its state or revers back to the default state when not clicked. | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Label | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-2-icon.png]] | ||
+ | | width="90%" | Label Colour | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-7-icon.png]] | ||
+ | | width="90%" | Show Component Label | ||
+ | |- | ||
+ | | colspan="2" | Controls if the component label is visible or not | ||
|- | |- | ||
| width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | | width="10%" align="center" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
− | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Label | + | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Component Label |
|- | |- | ||
|- | |- | ||
Line 116: | Line 204: | ||
| colspan="2" | | | colspan="2" | | ||
|- | |- | ||
− | | width="10%" align="center" | [[File:Fc9-type- | + | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] |
− | | width="90%" | | + | | width="90%" | Component label position |
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
Line 128: | Line 216: | ||
| 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" style="background-color:#EAE1EA;" | [[File:Fc9-conn-icon.png]] | ||
+ | | width="90%" style="background-color:#EAE1EA; color:#4B008D;" | Pin Label | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-16-icon.png]] | ||
+ | | width="90%" | Pin label position | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Set X Postion | ||
+ | |- | ||
+ | | colspan="2" | | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-type-14-icon.png]] | ||
+ | | width="90%" | Set Y Postion | ||
|- | |- | ||
| colspan="2" | | | colspan="2" | | ||
Line 155: | Line 262: | ||
| colspan="2" | | | colspan="2" | | ||
|} | |} | ||
+ | |||
+ | ==Component Source Code== | ||
+ | |||
+ | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Switch_Push_Button_2dgi.fcfx FC_Comp_Source_Switch_Push_Button_2dgi.fcfx] | ||
+ | |||
+ | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Switch_Push_Button_2dgi.fcfx FC_Comp_Source_Switch_Push_Button_2dgi.fcfx] |
Latest revision as of 11:42, 26 November 2024
Author | Matrix TSL |
Version | 15.0 |
Category | Switch |
Contents
Switch Push Button component
A simple digital push switch allowing latched and none latched operation. In embedded mode displays the connecting pin and pin status.
Version information
Library Version, Component Version, Date, Author, Info 15, 15.0, 30-07-24, MW, Fixed a bug to make sure switch starts in the off position 15, 15.0, 18-08-24, MW, Added option for simulation only 15, 15.0, 30-07-24, MW, Fixed a bug preventing custom lable posistion from updating on the fly
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
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
Note: if you want to use switch functions e.g. Active Low or debounce ,you must use the ReadState function and not use just an input.
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 |
Property reference
Component Source Code
Please click here to download the component source project: FC_Comp_Source_Switch_Push_Button_2dgi.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_Switch_Push_Button_2dgi.fcfx