Loading...
  Show Posts
Pages: 1 ... 1887 1888 [1889] 1890 1891 ... 2363
28321  Forum 2005-2010 (read only) / Syntax & Programs / Re: Stepper Motor Super Speed Control on: October 30, 2010, 03:29:33 pm
Yes, you could call setSpeed with new speed value, and then call step with the fixed number of steps. The setSpeed() method records a speed that step() uses to figure out the pause between steps.

Quote
Also, where can I find how fast the arduino processes a program?
A 16MHz Arduino processes each instruction in 62.5 nanoseconds. High level programming languages insulate you from knowing how many machine instructions a given statement will translate into, because various optimization levels will change how many machine instructions will be generated (or, more accurately, how many will be optimized out).

Why do you think this is important to know?
28322  Forum 2005-2010 (read only) / Syntax & Programs / Re: Stepper Motor Super Speed Control on: October 30, 2010, 06:49:10 am
If the number of steps per unit of time is known (and the potentiometer is controlling the unit of time), what is necessary is to figure out how long between steps.

Then, after each of those intervals of time has occurred, step again.

Look at the Blink Without Delay example for how to properly do this.
28323  Forum 2005-2010 (read only) / Syntax & Programs / Re: SD card shield <FAT.h> library help on: August 14, 2010, 07:36:03 am
You installed the library somewhere. Look in the directory where you installed the library. There are a bunch of .cpp and .h files. They are text files, so open them with you favorite editor.

The code to actually write to a file on the card is typically based on the Print class, which includes a println() function that adds a new line (which actually consists of a carriage return and a line feed).

Some editors interpret the carriage return only (\n) as a new line. Others expect both a carriage return and a new line (\r), in the correct order (and, no I never remember the correct order).
28324  Forum 2005-2010 (read only) / Syntax & Programs / Re: Function Prototype? (NEWBIE) on: October 31, 2010, 11:42:37 am
One of the more difficult aspects of C programming is assuring that the function prototype matches the actual definition.

To alleviate this problem, the Arduino IDE creates function prototypes for you. Normally, this works quite well. There are some situations, like functions with reference arguments, where it doesn't.
28325  Forum 2005-2010 (read only) / Syntax & Programs / Re: Count down timer disply while performing othertask on: October 31, 2010, 11:51:44 am
Quote
Im guessing the delay is what is screwing it up?
Good guess. Correct, even.

Look at the Blink Without Delay example for clues how to not use delay.

Basically, the "timer" isn't real. There is a variable with a value in it. At appropriate times, on each pass through loop, the value is incremented (or decremented) - whenever millis() returns a value that is significantly different from some stored value (the last time the value was changed).

At appropriate places in the code, display the value in the variable.
28326  Forum 2005-2010 (read only) / Syntax & Programs / Re: Count down timer disply while performing othertask on: October 31, 2010, 11:05:09 am
Is your timer based on delay()?

There is no reason that displaying a timer and getting keypresses at the "same" time can not be done.
28327  Forum 2005-2010 (read only) / Syntax & Programs / Re: where is Main()? (Newbie) on: October 31, 2010, 11:46:15 am
When the compiler runs, it creates blocks of code for each function. The position of the functions, and any code between functions, is irrelevant (except for forward references).

So, global variables can go before setup(), or between setup() and loop(). The loop function typically goes after the setup() function, but it does not need to.
28328  Forum 2005-2010 (read only) / Syntax & Programs / Re: Reading data via serial communication on: October 30, 2010, 02:37:45 pm
Quote
Those that can, do. Those that can't, ...
I just get tired of typing the same code over and over, so I suggested that the OP do a little searching. Using the string I suggested leads to code that works at any baud rate, with no delays, along with an explanation of what the code does, and what needs to be changed to use different start and end packet markers.
28329  Forum 2005-2010 (read only) / Syntax & Programs / Re: Reading data via serial communication on: October 30, 2010, 06:51:30 am
Quote
but just the one line of code eliminated my problem.
It didn't eliminate the problem for all baud rates - only your specific baud rate.

That's why end-of-packet markers are necessary.
28330  Forum 2005-2010 (read only) / Syntax & Programs / Re: Reading data via serial communication on: October 29, 2010, 08:04:36 am
Quote
so on S05150E
S will mean that we are STARTing to send data
05 will mean that we choose to store data on input[5] variable
150 will mean that  we chose number 150 to store ( on variable input[5])
E will mean that we inform chip that we are ENDING transmiting
This is a protocol. A specific definition of the data stream, and a set of instructions for parsing and using the data. Nicely done.

Quote
maybe there is a better idea on how to storing data to variables
The first step in defining a method is to define a protocol. You've done that.

Quote
can anyone help me on how can i do that?
The next step is to implement that protocol on both the sender and the receiver.

As you mentioned, you'll need a while loop on the Arduino that will read each character that is in the serial buffer. Within that while look, you'll need to test each character to see if it is the start character ('S'), or the end character ('E').

When it is the start character, initialize an array to hold the data (inData[0] = '\0';) and an index into that array (index = 0;). Set a flag (started = true;) that indicates that the start character has been received.

When it is the end character, set a flag (ended = true;) indicating that the end of the packet has been received, and break out of the while loop.

Otherwise, add the character to the array and increment the index, if started and not ended.

After the while loop, add a block to be executed if started and ended. In that block, you'll parse the array (which should contain 05150, for instance) and do something with the parsed data.

Search the forum for "started && ended" for an example of some code.
28331  Forum 2005-2010 (read only) / Syntax & Programs / Re: Problem with include Wire.h on: October 29, 2010, 04:42:22 pm
Try including Wire.h in the sketch, too.
28332  Forum 2005-2010 (read only) / Syntax & Programs / Re: Problem with include Wire.h on: October 28, 2010, 07:21:43 am
Quote
but return error in the line I include the Whire.h, what's wrong?
What returns an error? What is the error? What does the sketch that is using this library look like?
28333  Forum 2005-2010 (read only) / Syntax & Programs / Re: Serial.Read() Variable on: October 29, 2010, 08:39:18 pm
The Serial.read function returns a byte from the serial buffer. All the values in the range of a byte are valid. So, in order to be able to return an invalid value (to indicate that an attempt was made to read a value when none was available to be read, the function needs to return a larger value - one that can hold all possible legal values and one or more non-legal values. So, Serial.read() returns -1 (which doesn't fit in a byte) or the actual value read.

There is no type-mismatch.
28334  Forum 2005-2010 (read only) / Syntax & Programs / Re: Servo code question on: October 29, 2010, 04:29:31 pm
I'd still try an external power source for the servo. Connect the servo power supplies ground to the Arduino ground, too.
28335  Forum 2005-2010 (read only) / Syntax & Programs / Re: Servo code question on: October 28, 2010, 02:44:38 pm
Model name? Model number? Link to data sheet? Facts, man! We need facts!

We don't need no steeenking badges, but we do need data. smiley
Pages: 1 ... 1887 1888 [1889] 1890 1891 ... 2363