Push-Button not working in Momentary
Moderator: Benj
Push-Button not working in Momentary
I need to make a counter that goes from 0-9999 on 7seg quad display,that resets to 0 on 9999 and when the push button (which has to be in momentary state) is pressed it should stop counting ,and when its pressed again it should continue counting.
I have made it to work in Latching,but in momentary its counting only when I hold the button,which isnt the right way.
I'd really appreciate your help with this one
I have made it to work in Latching,but in momentary its counting only when I hold the button,which isnt the right way.
I'd really appreciate your help with this one
Last edited by HoX123 on Sun Oct 31, 2021 6:58 pm, edited 2 times in total.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Push-Button not working in Momentary
Hi HoX123.
Welcome to the forums.
Can you follow this post please?
Then if you get stuck we can help you further.
If Flowcode is up-to-date then the first part can of course be ignored.
Welcome to the forums.
Can you follow this post please?
Then if you get stuck we can help you further.
If Flowcode is up-to-date then the first part can of course be ignored.
Martin
Re: Push-Button not working in Momentary
I cant really use newer versions since my professor requests for us to use same version as him,sorry.
Last edited by HoX123 on Sun Oct 31, 2021 6:58 pm, edited 1 time in total.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Push-Button not working in Momentary
You posted in the Flowcode V8 section, So it's assumed you are using that version.
What version have you got?
Flowcode V7 will load V8 flowcharts.
We can't do your assignment for you, we can only steer you in the right direction.
Martin
Re: Push-Button not working in Momentary
I've never asked anybody to do my assigment,I said help me do it not do it for me.
My flowcode is v6,I've posted here first,and then when I saw that i posted in wrong section I posted it in V6 but only this post got approved and i didnt know how to delete a post that was pending approval
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Push-Button not working in Momentary
I never said you did, I just wanted state it in advance.
That's not an issue, I have moved the topic to the V6 section.
Regarding latching.
My suggestion would be to look up how logical operators in c work.
One of the logical operators will work with a variable, within a calculation Icon to do what you want it to do.
I.e You have an input variable called taster, and that will change (Toggle) each time the switch is pressed.
I have noticed you are reading the whole port.
You don want to do that.
You only need to read 1pin (Bit)
So you need to change the input properties from whole port to Single bit then select the pin that the switch is connected to.
The other thing I would recommend is how to correctly connect switches to microcontrollers.
This page on the wiki shows you how.
Martin
Re: Push-Button not working in Momentary
I'm still at the beggining,tried to figure it out through stopwatch example but we arent allowed to use Interrupt block since we havent done it in class.I've managed to make it start with push button but not to stop when pressed againmedelec35 wrote: ↑Sat Oct 30, 2021 2:28 pmI never said you did, I just wanted state it in advance.That's not an issue, I have moved the topic to the V6 section.
Regarding latching.
My suggestion would be to look up how logical operators in c work.
One of the logical operators will work with a variable, within a calculation Icon to do what you want it to do.
I.e You have an input variable called taster, and that will change (Toggle) each time the switch is pressed.
I have noticed you are reading the whole port.
You don want to do that.
You only need to read 1pin (Bit)
So you need to change the input properties from whole port to Single bit then select the pin that the switch is connected to.
The other thing I would recommend is how to correctly connect switches to microcontrollers.
This page on the wiki shows you how.
EDIT : I've finally managed to get it working using until loops and following ur advice.Only thing I need to fix right now,is when I turn on flowcode first time and run the simulation for the first time it beggins counting without presing taster,and when i stop simulation and run it again it works as intended,waiting my press on button to start counting.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Push-Button not working in Momentary
That's OK.
I understand you can't jump ahead of what you have not been taught.
Have you been taught about logical operators?
If not, the only other way I can think of is when the switch is detected, get a variable called Enable for example, to equal1, then a delay for say 500ms.
If the switch is detected again get the variable to change back to 0 etc.
Then within the branch that showschange it to
The important thing is the branch variable can't have the same variable that's in the input icon.
The other thing you need to do is on the system panel, right-click on the switch and select properties.
Change the operation from latching to momentarily.
This is so the simulator can show you if what you have done is working or not.
I understand you can't jump ahead of what you have not been taught.
Have you been taught about logical operators?
If not, the only other way I can think of is when the switch is detected, get a variable called Enable for example, to equal1, then a delay for say 500ms.
If the switch is detected again get the variable to change back to 0 etc.
Then within the branch that shows
Code: Select all
If:taster = 0
Code: Select all
If:Enable =1
The other thing you need to do is on the system panel, right-click on the switch and select properties.
Change the operation from latching to momentarily.
This is so the simulator can show you if what you have done is working or not.
Martin
Re: Push-Button not working in Momentary
What I dont understand,is where and how am I supposed to check if the switch is detected again.If i put it in the same decision as the first check if the switch is pressed,it will use that first time i pressed it so the variable enable will just become 1 and then go back to 0,and the counter wont start at all. Now when I press button it starts counting but stops only while Im holding it.Then without delays it works but u need to click it a between 2-5 times...guess atleast im making some sort of progress

Last edited by HoX123 on Tue Nov 02, 2021 8:42 pm, edited 1 time in total.
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Push-Button not working in Momentary
It's not easy to help as I have no way of knowing what you have been taught so far.
Have you been taught about bitwise or logical operations?
Basically, you will be using one variable (taster) within the Input.
The value will depend on if the switch has been pressed or not.
Every time the switch has been pressed, it will change the value of another variable (Enable) between 0 and 1.
If the Enable variable = 1 then counting can commence.
If the Enable variable = 0 then counting can commence.
If you have not been taught how toggle a variable using bit or logical operations, then the only other way I can think of is if the switch is detected (Taster will be 0 if the switch is active low) then add 1 to Enable.
Then you will need to think of a way to make the Enable variable change from a 1 back to a 0 of the value of Taster is 0 as the switch has been detected as pressed.
You can do that with a decision branch and a calculation icon.
Have you been taught about bitwise or logical operations?
Basically, you will be using one variable (taster) within the Input.
The value will depend on if the switch has been pressed or not.
Every time the switch has been pressed, it will change the value of another variable (Enable) between 0 and 1.
If the Enable variable = 1 then counting can commence.
If the Enable variable = 0 then counting can commence.
If you have not been taught how toggle a variable using bit or logical operations, then the only other way I can think of is if the switch is detected (Taster will be 0 if the switch is active low) then add 1 to Enable.
Then you will need to think of a way to make the Enable variable change from a 1 back to a 0 of the value of Taster is 0 as the switch has been detected as pressed.
You can do that with a decision branch and a calculation icon.
Martin