Page 1 of 1
.Return Variable
Posted: Fri Apr 17, 2020 11:38 am
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
Re: .Return Variable
Posted: Fri Apr 17, 2020 12:32 pm
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...
Re: .Return Variable
Posted: Fri Apr 17, 2020 6:04 pm
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 .....
Re: .Return Variable
Posted: Fri Apr 17, 2020 6:30 pm
by medelec35
Can you confirm if you see the 20 seconds value correctly displayed on LCD?
Re: .Return Variable
Posted: Fri Apr 17, 2020 7:04 pm
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?
Re: .Return Variable
Posted: Sat Apr 18, 2020 8:13 am
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!
Re: .Return Variable
Posted: Sat May 02, 2020 4:52 pm
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