Show Posts
Pages: 1 ... 43 44 [45] 46 47 ... 87
661  Using Arduino / Programming Questions / Re: Problem calling a function from another function on: September 26, 2012, 01:37:27 pm
The way I read your code:
Code:
void registerWrite(int whichPin, int whichState) {
  byte bitsToSend = 0;
  bitWrite(bitsToSend, whichPin, whichState); 
  shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);
The routine ALWAYS starts with bitsToSend at zero. If you called it with
Code:
  registerWrite(5, HIGH);
it will correctly set and transfer bit 5 to the shift register.
A second later your code in runAnimation reaches
Code:
  registerWrite(6, HIGH);
Because the bitsToSend starts with zero, bit 5 is now clear(low) again, as we set bit 6.

This is "simply" fixed by putting the word static in front. bitsToSend will now keep the value of 5 to what you set it to, until you explicitly reset it.
Code:
static byte bitsToSend = 0;

This does not explain why the test loop "seems" to work, but I suspect you expected each port to turn on in sequence and missed that the only one port on at a time was turned on when your expectation (from the way I read your code) shoudl have been that more and more turned on.
662  Using Arduino / LEDs and Multiplexing / Re: [Advice needed] Building a small BCD clock. on: September 26, 2012, 09:48:39 am
atmega328, 16 mhz crystal, two 22pf caps, three 100nF caps.
14 resistors, 14 LEDs.
A board to mount the stuff on.  And access to someone else's system with a serial line to program it. Easier if the atmega328 already has a bootloader programmed.
663  Using Arduino / Motors, Mechanics, and Power / Re: Choosing power supply for steppers on: September 26, 2012, 09:29:57 am
The datasheet shows the "Ohm law" relation - ie what voltage will reach maximum current. What one would like to know is the voltage the insulation of the windings can tolerate. A "modern" stepper driver chip does PWM to keep the current at the desired maximum level but pulses it with the supplied voltage which is several times higher. In theory the higher voltage will allow you to go for (slightly) higher max step speed and give a little more torque.

I suppose you can just turn the voltage up until it starts smoking, then use less than that on your next motor :-)

Alternativly use a conservative voltage (say 9V in your case) and if that is enough speed/torque for what you final machine is to do, fine. Otherwise beef it up until the motor or your courage gives up. You driver chip will propably limit you to 30V.
664  Community / Website and Forum / Re: Karma is back on: September 26, 2012, 09:08:42 am
<resigned sigh ....>
665  Community / Bar Sport / Re: Interstellar Travel on: September 26, 2012, 08:55:27 am
The Burj Khalif in Dubai is 800m tall. Another 200m and we're there. The video gave me no clue what so ever why the air should be 70 at the foot of the tower.
666  Community / Bar Sport / Re: Shop in a shipping container (somewhat off topic) on: September 17, 2012, 08:06:46 am
That was some heartwarming news. Something that actually keeps on giving, instead of requiring expensive parts/labour from the "generous" western countries.

The webpage says: "for $50,000, you can buy one directly from the designers" That seems like a steal, I think the price is only valid if resident in non-city regions of Africa. smiley-cool
667  Using Arduino / Programming Questions / Re: Why does it have to be static? on: September 17, 2012, 03:41:33 am
I really love the "Send us the code, before and after" "explain what you expect". 

I do the same. Hey, I even demand the same. (Years ago I was head of  support/QA in a company, the official bug report forms I designed had fields for this, with great success) I thought I was above such details this time. <beep> Wrong!

There is this great saying, that I use with friends/colleagues, when we hit an "impossible" problem/bug/behaviour in the systems we work with:

"Explain it to the teddy bear"

Usually, when explaining a problem in excruiating detail to the teddy bear (or a colleague  smiley-wink ) you suddenly see the problem from a new angle or discover a presumption you made that was never made explicitly clear.

And thus the error is discovereed, the problem solved. Humbly I realized my hidden assumption in this case, too.

So - the example in this thread will work.

My code (see the link) left the calling function (loop) and in again and the called function assumed(!) that the parameter it had gotten was unchanged by the caller. Which it wasn't as it is un-static.

I conclude it is very bad coding style for a function to assume that it can use the by reference parameters as (static) storage, between invokations of being called. Too aggressive in saving precious memory bytes. My excuse is that the function was always inline with global variable. As the linked thread says - I converted it to library, and this is where all probelms began. Before the variables were global but you cant do that with a library. I'll fix the code, and "waste" 3 bytes.

Thank you for reading. Now move along, there is nothing more to see here. smiley
668  Using Arduino / Programming Questions / Re: Why does it have to be static? on: September 17, 2012, 12:40:00 am
Damn. It just goes to show, when writing new and shorter code in the post, instead of doing a cut-n-paste from the real code, one introduces new errors. And there is one more error <sigh-  smiley-roll-blue > in my initial post. I was just gettng very very frustrated. Sorry. If you look at the real code (link in above post), you'll see that I do know the difference.

Still the problem is there.

When I write
Code:
static int P ;
  F ( &P ) ;
   :
void function F ( int *P) { *P = 42 ; }

it works fine

BUT when I use
Code:
/*dynamic*/ int P ;
 F ( &P ) ;
   :
void function F ( int *P) { *P = 42 ; }
I get "random" results
669  Using Arduino / Programming Questions / Re: Simple-yet-powerfull - Serial Command input with numbers on: September 16, 2012, 03:05:51 pm
(Embarassment  smiley-eek Found a bug in the float version. Now fixed. Original post edited.)
670  Using Arduino / Programming Questions / Re: Why does it have to be static? on: September 16, 2012, 02:46:02 pm
I just wrote this in hand to illustrae the essence. The actual code does use a different name. The actual code is http://arduino.cc/forum/index.php/topic,115174.0.html
671  Using Arduino / Programming Questions / Solved: Why does it have to be static? on: September 16, 2012, 02:05:56 pm
My main routine
Code:
static int P ;
function F ( &P ) ;
The function
Code:
void function F ( int *P) { P = 42 ; }
It fails mysteriously if the P is NOT declared static. It works for char data type, but not int or float.

(I was just browsing the GRBL software package where they have the same construction, and it works, presumably. Some time ago I did above and it failed, as I describe. A weak theory is that GRBL presumes a different toolchain to compile... but it still is the same compiler, right?)
672  Community / Bar Sport / Re: Interstellar Travel on: September 13, 2012, 11:36:26 am
Too late for me - I wont be buying a ticket.
 smiley-wink
673  Using Arduino / Motors, Mechanics, and Power / Re: More than 1 servo on: August 26, 2012, 02:17:38 pm
So... either you have a very bad/burned AVR-chip or your wiring is wrong or faulty - bad powersupply, a loose connection, unexpected short. (Possibly one servo is bad, messing up activity the other one)

Suggestion. Rebuild it. Take all wires off, rewire, cleaner, more carefully.
674  Community / Bar Sport / Re: Your latest purchase on: August 24, 2012, 10:59:58 am
You want mobile hackerspace, have a look at my truck smiley
Oooohh .... nice. A normal car driving license isn't enough, I presume.

Where is the Arduino?
675  Using Arduino / Motors, Mechanics, and Power / Re: (RPM) output 1600 pulses = 1 RPM on: August 19, 2012, 03:26:08 pm
The usual Stepper library is blocking, that is, it will not continue until it has given the number of steps.

The solution is a loop that closely resembles the "BlinkwithoutDelay" example. Instead of togging pin13 you call step(1) whenever the "millis()-timer" differnece exceeds the timing threshold. In the loop you also do a an analog read on every pass and calculate an updated value for the timing threshold.

Do not call Serial.print on every pass. This takes too much time. Only call it every 1000 millisec (which means you have another section with another timer that triggers once a second - have a look at  Blink Two LED without delay)

Enjoy
Pages: 1 ... 43 44 [45] 46 47 ... 87