strange code ?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Drakkor
Posts: 41
Joined: Sun Dec 30, 2012 9:34 pm
Has thanked: 5 times
Been thanked: 4 times
Contact:

strange code ?

Post 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.........
Last edited by Drakkor on Wed Oct 16, 2013 3:24 pm, edited 1 time in total.

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: strange code ?

Post 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

Drakkor
Posts: 41
Joined: Sun Dec 30, 2012 9:34 pm
Has thanked: 5 times
Been thanked: 4 times
Contact:

Re: strange code ?

Post by Drakkor »

Jonny, Thanks. I will send the code when I get off work.

Drakkor
Posts: 41
Joined: Sun Dec 30, 2012 9:34 pm
Has thanked: 5 times
Been thanked: 4 times
Contact:

Re: strange code ?

Post 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 : )
Attachments
StrobeWORKS.fcf
(19.69 KiB) Downloaded 232 times

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 63 times
Been thanked: 290 times
Contact:

Re: strange code ?

Post 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

Drakkor
Posts: 41
Joined: Sun Dec 30, 2012 9:34 pm
Has thanked: 5 times
Been thanked: 4 times
Contact:

Re: strange code ?

Post by Drakkor »

Jonny, Thank you. I appreciate all the help and information :D

Post Reply