Page 1 of 1

can you make switch array e-block into "toggle button"?

Posted: Thu Nov 24, 2016 11:46 pm
by Late347
using pic16f1937 and switch array with 8 black buttons as the e-block.

I'm using flowcode7.

Currently I was mosltly using the switch array as direct input such that when the switch button is being continuously pressed -->something happens. Whe nthe button is released, There is no input.

I was wondering if it is possible to easily change the functionality of this push-release button in flowcode such that...

when nothing is being pressed and proram starts -->boolean variable in flowcode (value 0) is tied into one of the buttons, and value =0

1.)when button is pressed once ---> boolean =1
when button is released ---> boolean = 1

2.)when button is pressed second time -->boolean = 0
when button is released --->boolean =0

3.) when button is pressed third time -->boolean = 1
when button is released -->boolean =1

etc.

Re: can you make switch array e-block into "toggle button"?

Posted: Fri Nov 25, 2016 8:21 am
by QMESAR
Hi

I am not 100% sure if i understood you correctly however to my understanding you are looking to something like this
read the push button save its state to a bool value(create a variable of bool type in the variable editor) and check if the button was pressed or not and accordingly branch in your code to a code section for when the button is pressed and when it is not pressed
:D

Re: can you make switch array e-block into "toggle button"?

Posted: Fri Nov 25, 2016 11:49 am
by Late347
Ok thanks for suggestion.

I tried to add input device, the switch array e-block

-click properties on the switch array (push) component on the dashboard

-click the "operation" part (this is what I need, I think...?)
Because it turns the button from push-release mode, into toggle-button. "Toggle buttons" in my opinion function such that you press the button once. Then the button activates the True state, and stays at that state. When you push the button again, the button releases and activates False state.

-also "polarity" active high/ low (what does this do?)

-also "debounce" (what does this do?)

Re: can you make switch array e-block into "toggle button"?

Posted: Fri Nov 25, 2016 11:59 am
by QMESAR
In my opinion the code example I have given you works regardless of the type of push button you use :D
also "polarity" active high/ low (what does this do?)
The code check if the signal is 3.3 or 5V(depeding on you voltage you use) when the button is pressed or zero volt when the button is pressed and this depends on how you wire the button electrically and then you set your code to fit the electrical characteristics of your Button
also "debounce" (what does this do?)
you have to give a small delay before you read the button as the micro is much faster that you pressing the button which results in an unreliable read of the state of the button with the debounce time you make sure you read the button correctly

Re: can you make switch array e-block into "toggle button"?

Posted: Fri Nov 25, 2016 5:52 pm
by Benj
Hello,

To add to QMESAR's reply.

The operation mode property simply defines the way the simulation will behave. Use QMESARs example to allow you to treat momentary push buttons as latching push buttons in software.
also "polarity" active high/ low (what does this do?)
We have a electrical schematic demonstration of the two configurations here - assuming a push to make switch.

Wiki - Switches
also "debounce" (what does this do?)
When you press a switch the metallic contacts of the switch can bounce several times before settling (think of the mechanical click you get when you press a switch, the click is likely an audible sign of the bounce). A microcontroller can potentially see this bounce as individual switch presses which might cause problems in your programs. The debounce time sets how long to wait for a stable signal. So if the debounce time is set to 10 milliseconds then the input signal needs to be stable for at least 10 milliseconds before the macro will return a value. If the value is constantly changing every millisecond then the macro will never return. Setting the debounce time property to 0 will switch off the debounce functionality e.g. for high speed comms input or other non mechanical related inputs.