Yorkshire England
Offline
Sr. Member
Karma: 1
Posts: 253
Arduino good init
|
 |
« Reply #30 on: March 19, 2012, 04:25:34 am » |
Thanks.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 226
Posts: 14106
Lua rocks!
|
 |
« Reply #31 on: March 19, 2012, 05:05:04 am » |
For me, the most peculiar thing about C is that the missing condition in for(;;) evaluates to true. Yeah good point. Although if it didn't, it would be pretty useless. I suppose the logic is: Have a starting statement, or nothing. Have a condition, or no condition (in which case keep going). Have an end-of-loop statement, or nothing.
|
|
|
|
|
Logged
|
|
|
|
|
Pittsburgh, PA, USA
Offline
Faraday Member
Karma: 33
Posts: 3017
I only know some basic electricity....
|
 |
« Reply #32 on: March 19, 2012, 09:09:39 am » |
"C code for I want to be fairly obtuse" int indx = 0; while(! indx [outstr] == 0) { indx[outstr] = indx[instr]; indx = indx + 1; } LOL! So, what's your point?
|
|
|
|
|
Logged
|
Examples can be found at Learning in the Main Site and at the Playground
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 282
Posts: 15443
Measurement changes behavior
|
 |
« Reply #33 on: March 19, 2012, 09:58:11 am » |
lol its really both
It's not unlike a soldering iron, a useful tool if used properly, but it can definitly burn you if your not careful. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
field road, jupiter creek
Offline
Sr. Member
Karma: 2
Posts: 342
Arduino rocks
|
 |
« Reply #34 on: March 20, 2012, 10:02:12 am » |
How do this kind of recursion in C? Procedure Tree; {(x, y: integer; dir: real; level: integer)} Var xnew, ynew: integer; Begin If level > 0 Then Begin xnew := round(level * Scale * cos(dir)) + x; ynew := round(asp * level * Scale * sin(dir)) + y; PenSize(level, level); MoveTo(x, y); LineTo(xnew, ynew); tree(xnew, ynew, dir + inc + Randomize(2), level - 1); tree(xnew, ynew, dir - inc + Randomize(2), level - 1); End End;{Tree}
This draws tree's! Quite nice ones as well! In 3D I have 1 on the X/Z plane and another on the Y/Z plane, other wise they disappear into a vertical line. I use this kind of recursion with linked lists a lot.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
|
 |
« Reply #35 on: March 20, 2012, 10:05:42 am » |
Recursion is simple, but it can be a RAM-hog, so beware. unsigned long factorial (unsigned long n) { return (n == 0) ? 1 : factorial (n - 1) * n; }
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Belgium
Offline
Edison Member
Karma: 34
Posts: 1118
Arduino rocks; but with my plugin it can fly rocking the world ;-)
|
 |
« Reply #36 on: March 20, 2012, 10:08:02 am » |
Yust write in C like. The only methods I see problem with are: PenSize(level, level); MoveTo(x, y); LineTo(xnew, ynew); Because there is no pure c alternative. If you uses Visual studio there are but I wouldn't know any alternative for Arduino. Bets regards Jantje How do this kind of recursion in C? Procedure Tree; {(x, y: integer; dir: real; level: integer)} Var xnew, ynew: integer; Begin If level > 0 Then Begin xnew := round(level * Scale * cos(dir)) + x; ynew := round(asp * level * Scale * sin(dir)) + y; PenSize(level, level); MoveTo(x, y); LineTo(xnew, ynew); tree(xnew, ynew, dir + inc + Randomize(2), level - 1); tree(xnew, ynew, dir - inc + Randomize(2), level - 1); End End;{Tree}
This draws tree's! Quite nice ones as well! In 3D I have 1 on the X/Z plane and another on the Y/Z plane, other wise they disappear into a vertical line. I use this kind of recursion with linked lists a lot.
|
|
|
|
|
Logged
|
|
|
|
|
field road, jupiter creek
Offline
Sr. Member
Karma: 2
Posts: 342
Arduino rocks
|
 |
« Reply #37 on: March 20, 2012, 10:13:57 am » |
Recursion is simple, but it can be a RAM-hog, so beware. Oh hell yeah! Ages ago I wrote a "Galaxy" builder, around the galactic centre it randomly places stars, then puts planets around the stars, moons around the planets. A friend of mine was messing around with the build dialogue. I wasn't really paying much attention at first, till I noticed he was punching in really big numbers for star density, that got multiplied by (100 * random(100))!! He says, "gee, this is getting slower!" This was on a Mac IIci, with only 8M of RAM!
|
|
|
|
|
Logged
|
|
|
|
|
field road, jupiter creek
Offline
Sr. Member
Karma: 2
Posts: 342
Arduino rocks
|
 |
« Reply #38 on: March 20, 2012, 10:24:20 am » |
With nootropics TVout library
MoveTo(x, y); LineTo(xnew, ynew);
turns into
TV.draw_line(x,y,x,y); TV.draw_line(x,y,xnew,ynew);
|
|
|
|
|
Logged
|
|
|
|
|
Pittsburgh, PA, USA
Offline
Faraday Member
Karma: 33
Posts: 3017
I only know some basic electricity....
|
 |
« Reply #39 on: March 20, 2012, 11:01:59 am » |
When you call a function it saves the return address on the stack and any variables local to the function go on the stack so when a function calls itself over and over you better have more than 2k for everything!
|
|
|
|
|
Logged
|
Examples can be found at Learning in the Main Site and at the Playground
|
|
|
|
field road, jupiter creek
Offline
Sr. Member
Karma: 2
Posts: 342
Arduino rocks
|
 |
« Reply #40 on: March 20, 2012, 06:45:11 pm » |
Back when I was writing business software for Apple II, how much RAM you think we had left out of 48K?
I mainly use my Mega's for stuff like this.
|
|
|
|
|
Logged
|
|
|
|
|
Pittsburgh, PA, USA
Offline
Faraday Member
Karma: 33
Posts: 3017
I only know some basic electricity....
|
 |
« Reply #41 on: March 21, 2012, 01:31:48 am » |
I cut my teeth on less than that but it's in range for 1980 or so. The main thing is to constrain how far the code should need to go. For small machines I can suggest Forth-79, it's amazing how much you can do with it in tight space.
With some systems it seemed I could write small useful programs with an executable 100's of bytes long and then by the mid-80's on the preferred setups it was seeming like the easy minimum was 8K without taking extra steps to cut the code size down. The more memory we got, the much more got used for extras that count less.
|
|
|
|
|
Logged
|
Examples can be found at Learning in the Main Site and at the Playground
|
|
|
|
Belgium
Offline
Edison Member
Karma: 34
Posts: 1118
Arduino rocks; but with my plugin it can fly rocking the world ;-)
|
 |
« Reply #42 on: March 21, 2012, 07:48:23 am » |
I started off on a commodore 64K. That was plenty of memory in those days. Can you understand how puzzled I am having 8 GIG of memory now and I still feel like more  The recursive code uses 2 integers that makes up 8 bytes plus 2 bytes for the return address makes 10 in total. In 1 K of memory that is still a recursion of 102 deep. Best regards Jantje
|
|
|
|
|
Logged
|
|
|
|
|
field road, jupiter creek
Offline
Sr. Member
Karma: 2
Posts: 342
Arduino rocks
|
 |
« Reply #43 on: March 21, 2012, 08:05:19 am » |
I know what you mean!
Some of my code I've run under linux now I have like 10 times the RAM my Mac+ had...
So tell me, how does
Procedure (value:integer);
differ in C from
Procedure Calc(var:value:integer);
In the first case, "value" gets pushed onto the stack, in the second, the address for "value" gets pushed onto the stack and you don't have to worry about making "Calc" a function? ie
result := Function Calc(value);
The other thing that I'm still coming to grips with is records!
How do I do rcords here in Arduino?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
|
 |
« Reply #44 on: March 21, 2012, 08:09:32 am » |
How do I do rcords here in Arduino? Do you mean "struct"s ?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|