.Return Variable

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

Moderator: Benj

Post Reply
Xbeejunior
Posts: 28
Joined: Tue Dec 10, 2013 9:32 am
Has thanked: 9 times
Been thanked: 3 times
Contact:

.Return Variable

Post by Xbeejunior »

Hi Benj, I am trying to get a .Return variable back into the main program from a macro, it should then (here for the test) at certain minutes, the port B1 briefly set to high, you can tell me what I do wrong !?
Please look in "Main" in the macro "Zeit_auslesen" and the "If" decision below it ....
Thanks in advance
Attachments
Test Return Variable.fcfx
(33.92 KiB) Downloaded 151 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: .Return Variable

Post by kersing »

Something to take into account, you should always set the .Return to a value. In your macro you are only setting a value is Test equals 1, not if it is set to any other value.

Nothing obvious looks wrong with the code, however during simulation I notice in "Zeit_Datum_Anzeigen_2" you loop 500 times to update the display. This takes a long time in simulation and given the amount of I2C communication involved might take some time in real life as well...
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Xbeejunior
Posts: 28
Joined: Tue Dec 10, 2013 9:32 am
Has thanked: 9 times
Been thanked: 3 times
Contact:

Re: .Return Variable

Post by Xbeejunior »

Thank you Kersing, but I do not know if I understand you, I have set .Return to minutes and I want to query this variable in the main program, but this does not work because B1 never switches, so the requested minutes are not returned, I just want to try to return the minutes from the macro "Zeit_auslesen" to the main program so that I can use the "If" decision.....
P.S. Variable test is global, variable .Test is local and only intended for return .....

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: .Return Variable

Post by medelec35 »

Can you confirm if you see the 20 seconds value correctly displayed on LCD?
Martin

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: .Return Variable

Post by kersing »

You only return a valid value if Test is set to 1. In other cases .Return is not set to a value in your Macro due to the decision at the end of the macro. For all other values of Test you are calling another macro from your macro.
If you always want to set the return value you need to move the assignment out of the decision block.
However, I am wondering if your code is running the decision when you expect it due to the loop in the first macro called from your main. That updates the display very often, is once not sufficient?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Xbeejunior
Posts: 28
Joined: Tue Dec 10, 2013 9:32 am
Has thanked: 9 times
Been thanked: 3 times
Contact:

Re: .Return Variable

Post by Xbeejunior »

medelec35 wrote:Can you confirm if you see the 20 seconds value correctly displayed on LCD?
the time was not displayed correctly you are right, I once initialized the I2C too much, but that was only an attempt, it didn't work before, I just forgot to delete it ... thanks!


kersing wrote:You only return a valid value if Test is set to 1. In other cases .Return is not set to a value in your Macro due to the decision at the end of the macro. For all other values of Test you are calling another macro from your macro.
If you always want to set the return value you need to move the assignment out of the decision block.
However, I am wondering if your code is running the decision when you expect it due to the loop in the first macro called from your main. That updates the display very often, is once not sufficient?
the decision should only be made from the macro call ".Test = Zeit_Auslesen".
The macro call "Time_Date_Show" should only display the date / time for approx. 20 seconds until the awning is in position, the program then sets "Test = 1", because only the time should be brought into variables without the LCD activate.
When the program was finished I wanted to retract the awning at a certain time, you can of course do it differently, I just wanted to learn and know how it is with the .Return variable.
I'll keep trying tonight .... thanks!

Xbeejunior
Posts: 28
Joined: Tue Dec 10, 2013 9:32 am
Has thanked: 9 times
Been thanked: 3 times
Contact:

Re: .Return Variable

Post by Xbeejunior »

I found the problem after trying 10,000 different attempts, but the attempts were all in vain because somehow a compile-time error always occurred!
My LCD display is connected in 4-bit mode, i.e. the byte that is to be read in must be rotated and broken down into two nibbles, the higher-order bits being filled with zeros.
Here was the error somewhere, because only the number 0-15 could be shown on the display, then it continued with 10, 11, 12 etc. After I finally deleted the whole macro and created the same macro again, everything worked as it should, the minutes 0-59 were then correctly returned and displayed!
Could the error come because the program was originally made with Flowcode 6 and I processed it further with F8 !? But otherwise everything went perfectly !? Well it choked, but it was really annoying :)
Sometimes the program is simply not handed over correctly, but I can no longer fully understand whether it is because e.g. more than one instance of F8 is open or copying macros or sharing programs .......
Greetings

Post Reply