Page 1 of 1

Mandatory button and macro

Posted: Sun Feb 26, 2012 7:03 pm
by JanB
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

Re: Mandatory button and macro

Posted: Sun Feb 26, 2012 7:15 pm
by JohnCrow
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/mmforum ... 170#p32170

Re: Mandatory button and macro

Posted: Sun Feb 26, 2012 7:25 pm
by JanB
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

Re: Mandatory button and macro

Posted: Sun Feb 26, 2012 8:19 pm
by dazz
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

Re: Mandatory button and macro

Posted: Sun Feb 26, 2012 8:21 pm
by medelec35
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

Re: Mandatory button and macro

Posted: Mon Feb 27, 2012 9:31 am
by JanB
Many thanks for the answers, I will get to work with it.

Is it also possible to make the attached files in this post http://www.matrixmultimedia.com/mmforum ... 170#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

Re: Mandatory button and macro

Posted: Mon Feb 27, 2012 1:08 pm
by dazz
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

Re: Mandatory button and macro

Posted: Mon Feb 27, 2012 7:00 pm
by JanB
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

Re: Mandatory button and macro

Posted: Mon Feb 27, 2012 7:40 pm
by dazz
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

Re: Mandatory button and macro

Posted: Mon Feb 27, 2012 8:03 pm
by JanB
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.

Re: Mandatory button and macro

Posted: Mon Feb 27, 2012 8:17 pm
by medelec35
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:
http://www.matrixmultimedia.com/mmforum ... =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?

Re: Mandatory button and macro

Posted: Mon Feb 27, 2012 8:38 pm
by JanB
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.

Re: Mandatory button and macro

Posted: Tue Feb 28, 2012 7:07 pm
by JanB
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

Re: Mandatory button and macro

Posted: Tue Feb 28, 2012 9:03 pm
by medelec35
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?

Re: Mandatory button and macro

Posted: Wed Feb 29, 2012 7:16 am
by JanB
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