Page 1 of 1
strange code ?
Posted: Wed Oct 16, 2013 2:16 pm
by Drakkor
Hi. I am on my tiny phone typing so I'll get to the question. I am ramping an led up and down like a beacon. I have a main, an interrupt and two macros...rampup and rampdown. In both macros, there is a while loop. When I look at the text in the while loop box, it says var1 《 rampup.rampTo instead of some number or other variable? I don't see any c code and the program works great. I just need to know where this macro name dot To came from? I can't remember and it is driving me nuts that I don't know : ( Thanks.........
Re: strange code ?
Posted: Wed Oct 16, 2013 2:35 pm
by JonnyW
Hello.
It sounds like a parameter to the macro, either that or it is a local variable or constant. It is difficult to know without any code to see though.
Cheers,
Jonny
Re: strange code ?
Posted: Wed Oct 16, 2013 3:21 pm
by Drakkor
Jonny, Thanks. I will send the code when I get off work.
Re: strange code ?
Posted: Thu Oct 17, 2013 12:20 am
by Drakkor
Jonny. You were correct : ) I posted the code here. You'll have to ignore the comments I added in the code as they are just useless except to me. I wonder also, why not just use the variables in this case as the parameters seems like more work? Maybe I am missing something though? The original code was used for a single red led to look like a beacon on an RC plane. It also flashed two bright white leds for strobes. Thanks : )
Re: strange code ?
Posted: Thu Oct 17, 2013 12:29 pm
by JonnyW
I don't know how the original author wanted things to work, but personally I use global variables as little as possible.
Passing values through parameters to macros allows for flexibility, and can in some cases cut down on code size, as you do not need subtle variants of macros, so you are producing more reusable code. It also helps with development as you can easily change values where the function is called, rather than somewhere deep in its internals.
In short, it is considered better programming practice to keep your code tidy and flexible than to hard-code everything in a very rigid system.
Jonny
Re: strange code ?
Posted: Thu Oct 17, 2013 4:31 pm
by Drakkor
Jonny, Thank you. I appreciate all the help and information
