Mandatory button and macro

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

JanB
Posts: 34
Joined: Thu Feb 23, 2012 7:33 pm
Contact:

Mandatory button and macro

Postby JanB » Sun Feb 26, 2012 7:03 pm

Hello,

I have created two macros Macro A and Macro B with LED patterns. I need to "call / activate" them with one mandatory switch.

Situation:
Macro A
Macro B
(later more macros)

If I press the mandatory switch is has to load Macro A. If I press for the seccond time the mandatory switch it has to load Macro B.

A example what I want to make is this: http://www.youtube.com/watch?v=LTq5uSH73QE

I have now two working macros (it will be more) but I dont understand how to configure the mandatory switch to do this in MAIN. If someone can help me or give me a example then I appreciate this very much. I'm stuck in this :-(

Jan

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 381 times
Been thanked: 716 times
Contact:

Re: Mandatory button and macro

Postby JohnCrow » Sun Feb 26, 2012 7:15 pm

Hi JanB

Maybe this post will help you
A short press on the button will do one option and a longer press will do the second option

http://www.matrixmultimedia.com/mmforums/viewtopic.php?f=46&t=10183&p=32170#p32170
1 in 10 people understand binary, the other one doesn't !

JanB
Posts: 34
Joined: Thu Feb 23, 2012 7:33 pm
Contact:

Re: Mandatory button and macro

Postby JanB » Sun Feb 26, 2012 7:25 pm

Hi JohnCrow,

Thanks for your answer but I can't open this files (something with: pic8 defenition file is corrupted)

What I read in your answer is that this can solve my "problem" but I can't open it.

Regards,

Jan

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 514 times
Been thanked: 467 times
Contact:

Re: Mandatory button and macro

Postby dazz » Sun Feb 26, 2012 8:19 pm

Hi
this is the switch read part of the post john mentioned, not the original but changed to what i needed im posting it as a jpg image so you should be able to see it ,medelec created the original
hth
Attachments
pcbtimer.fcf - Main.JPG
(58.43 KiB) Downloaded 3898 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8475
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3485 times
Contact:

Re: Mandatory button and macro

Postby medelec35 » Sun Feb 26, 2012 8:21 pm

Another way is to use a variable called Pattern for example. Each time button is pressed then Pattern = Pattern +1 : if button is still pressed then wait until button is released: then
if Pattern>2 : Pattern = 1
Then you could use the switch function to call a macro that will be for a specific pattern.
So if case = 1 then call pattern1
case = 2 then call pattern2

Or you can just use decision branches.
IF Pattern = 1 :Call Pattern1
IF Pattern = 2 :Call Pattern2

You could add a lot of additional patterns both of these ways.

Martin
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JanB
Posts: 34
Joined: Thu Feb 23, 2012 7:33 pm
Contact:

Re: Mandatory button and macro

Postby JanB » Mon Feb 27, 2012 9:31 am

Many thanks for the answers, I will get to work with it.

Is it also possible to make the attached files in this post viewtopic.php?f=46&t=10183&p=32170#p32170 in that way that I can open them. I would appreciate that very much.

I can open all files on this forum but except this three files. (maybe this files are made in a newer version from flowcode)

I'm using a PIC12F629

Regards,

Jan

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 514 times
Been thanked: 467 times
Contact:

Re: Mandatory button and macro

Postby dazz » Mon Feb 27, 2012 1:08 pm

try this, i use flowcode 5 so you probably cant open the charts, so i posed an image hth

forgot to say insert you own macros etc
Attachments
Flowcode1 - Main.JPG
(40.05 KiB) Downloaded 3870 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

JanB
Posts: 34
Joined: Thu Feb 23, 2012 7:33 pm
Contact:

Re: Mandatory button and macro

Postby JanB » Mon Feb 27, 2012 7:00 pm

Thanks for your answer.

I try this but it seems not to work what I want to have / do. Attached is the Flowcode file, maybe someone can take a look at it. I think what I want to have is very simple, but it cant figure out how to do this.

Jan
Attachments
One Mandatory button call different macros V1.fcf
(8.5 KiB) Downloaded 167 times

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 514 times
Been thanked: 467 times
Contact:

Re: Mandatory button and macro

Postby dazz » Mon Feb 27, 2012 7:40 pm

noticed i missed out a loop, which waits until the button is released , it makes the whole thing more stable, basically short press does pattern 1 long press does pattern 2, just add the its labeled in the pic below , does it now do what you need it too
hth
Attachments
One Mandatory button call different macros V1.fcf - Main.JPG
(52.1 KiB) Downloaded 3860 times
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

JanB
Posts: 34
Joined: Thu Feb 23, 2012 7:33 pm
Contact:

Re: Mandatory button and macro

Postby JanB » Mon Feb 27, 2012 8:03 pm

Thanks for trying to help me out.

Remeber that I want to program someting like this: http://www.youtube.com/watch?v=LTq5uSH73QE

So, when I press the mandatory button is has to call Patern1, when I press a second time the same button it has to call Pattern2, and so on with more Patterns to come.

I'm using a PIC12F629

Attached is the file version 2 as made in the last post.
Attachments
One Mandatory button call different macros V2.fcf
(9 KiB) Downloaded 165 times
Last edited by JanB on Mon Feb 27, 2012 8:17 pm, edited 1 time in total.

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8475
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3485 times
Contact:

Re: Mandatory button and macro

Postby medelec35 » Mon Feb 27, 2012 8:17 pm

Hi Jan,
Here are two different ways of changing the pattern each time switch is pressed.
I'm not sure if you wanted pattern to keep being repeated (One Mandatory button call different macros V3.fcf) until you press switch just like in the video you posted a link to?

Or pattern should just stop (One Mandatory button call different macros V2.fcf) until switch is pressed then pattern changes, just like the flowchart you posted.

Either way The Flowcharts I have posted also allow more patterns (an unlimited amount) to be easily added.

If you want the pattern to be constantly repeated, but want to choose stop the pattern then in One Mandatory button call different macros V3.fcf,
Then change Count = 1 to Count = 0
Also to change pattern just hold switch in until LED's stay out.

The ideas other posters posted are also a very good idea and are not wrong at all!. I just wanted to post an alternative idea, so give you more choice.

One other thing. You hardware would not work because your Configuration setting are wrong.

I have guessed you want to use the internal oscillator?
And not use a pull-up resistor connected to MCLR?
So have altered the settings just for that.

Take a look at:
viewtopic.php?f=26&t=6936
For help on configuration settings.

Martin

Edit: Opps I did not chage the oscillator speed to 4MHz. that is now done on both flowcharts.
So if you plan on using them with internal osc. then you will need to download them again.

What is the specs. e.g osc type and speed. using a crystal or internal oscillator?
Attachments
One Mandatory button call different macros V2.fcf
Now set osc to 4MHz
(10 KiB) Downloaded 140 times
One Mandatory button call different macros V3.fcf
Now set osc to 4MHz
(10 KiB) Downloaded 141 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JanB
Posts: 34
Joined: Thu Feb 23, 2012 7:33 pm
Contact:

Re: Mandatory button and macro

Postby JanB » Mon Feb 27, 2012 8:38 pm

YES we are closer :-) Thanks for this work :-)

I will tomorow test the both files in Proteus and make a decission wich one I want to use. I also going to "read" the file's so I can learn to understand them.

It is true that the hardware in this file's is not working, I have to change that. This also cost me two day's to find this out :-) In Proteus the program (hex file) never start. In the attachment you can see how I get my PIC12F629 to work with Proteus. I have the hardware setup, now the program :-)

Agian many thanks to all for helping me out.

Greetings,

Jan

Attached are two pictures for the configuration for a PIC12F629 to work in Proteus.
Attachments
25-2-2012 12-04-28.png
25-2-2012 12-04-28.png (24.82 KiB) Viewed 6436 times
25-2-2012 12-03-30.png
25-2-2012 12-03-30.png (13.1 KiB) Viewed 6436 times

JanB
Posts: 34
Joined: Thu Feb 23, 2012 7:33 pm
Contact:

Re: Mandatory button and macro

Postby JanB » Tue Feb 28, 2012 7:07 pm

I decide to use "One Mandatory button call different macros V3.fcf" because this solution is working very fine.

I have now more patterns (macros) and it works very well. I have only one more question: is it also possible when I push the button then it has to go immediately to the next macro (pattern) whatever macro or loop is running. I try to work with interupts but I think this is not the solution to do this.

Agian many thanks for helping me out.

Jan

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8475
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2433 times
Been thanked: 3485 times
Contact:

Re: Mandatory button and macro

Postby medelec35 » Tue Feb 28, 2012 9:03 pm

Glad its working for you. thanks for the update.

JanB wrote:is it also possible when I push the button then it has to go immediately to the next macro (pattern) whatever macro or loop is running. I try to work with interupts but I think this is not the solution to do this.


Unfortunately I can't get the port interrupt on GP1 to work in V4 or V5 so here is one alternative which may be what your after?
Attachments
One Mandatory button call different macros V4.fcf
(11.5 KiB) Downloaded 160 times
Martin

If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.

JanB
Posts: 34
Joined: Thu Feb 23, 2012 7:33 pm
Contact:

Re: Mandatory button and macro

Postby JanB » Wed Feb 29, 2012 7:16 am

Aha :-) now I see it, I was staying in MAIN and not made any modifications in Pattern1. I understand now how this works, thanks agian for your help.

Jan