Show Posts
Pages: 1 ... 13 14 [15] 16 17 ... 289
211  Using Arduino / Programming Questions / Re: Possible use of function. on: August 05, 2014, 02:29:19 am
Quote
The problem is if I want to add another switch I have to write the same Function again to reference a different switch pin etc.
Is there way to give the function the ability to take multiple inputs at the same time and give multiple outputs? Such as different debounced button states? The purpose is just to simplify the code for 8 - 10 buttons which need debouncing.
Put the switch pins, last and current  in arrays then you only need to pass the index to the arrays.
212  Using Arduino / Programming Questions / Re: Modify the program "Blink without Delay" to count down and up on: August 05, 2014, 02:23:46 am
Code:
    i = i - 5;   
    interval = interval - i;
What will happen to the value of interval when i goes negative ?

Try printing i and interval just before the test for the value of interval
213  Using Arduino / Programming Questions / Re: print only new sensor data on: August 05, 2014, 01:48:32 am
If you only want to put the data in the database when it has changed, then each time you read it save it in a variable.  Next time you read the data compare it with the previous saved data and only put it in your database if it has changed.

Note, however, that the data from the GPS may fluctuate slightly on each read even if the unit has not moved.  You might like to consider only putting it in the database if it has changed by a significant amount.  Something like this
Code:
if abs( (newData - prevData) ) > 10)
  {
    //code to put the data in the database
  }
214  Using Arduino / Programming Questions / Re: Re-purposing the code for a digital potentiometer? on: August 05, 2014, 01:36:57 am
You should only need to change the pin numbers to match the Mega, not the code.
215  Using Arduino / Programming Questions / Re: Re-purposing the code for a digital potentiometer? on: August 04, 2014, 04:47:40 pm
The equivalent pins on the Mega are

51 (MOSI)
52 (SCK)
53 (SS)

See http://arduino.cc/en/Main/ArduinoBoardMega2560

I have not looked at the link to the code for the Uno but it should just be a matter of substituting the Mega pin numbers for the equivalent Uno ones in the code.
216  Using Arduino / Programming Questions / Re: Stopping a Servo Sweep. on: August 04, 2014, 04:29:27 pm
I am sure that you realise that the problem is caused by the use of delay() within the for loops which means that for nearly 4 seconds the program is tied up and cannot read the input.  The solution is not to use delay() for the timing but to use the principle shown in the BlinkWithoutDelay example.  This involves starting an action, such as moving the servo then checking frequently (each time through loop()) whether it is time to do something else, such as moving the servo again.  If not then do something else such as checking an input and acting on it,
217  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 04, 2014, 02:43:44 pm
Quote
Actually, no. as long as you're consistent in reading and writing.
That seems no different to me than being consistent using lowByte() and highByte() and reading and writing.
218  Using Arduino / Programming Questions / Re: valve system code (servo help) on: August 04, 2014, 12:32:31 pm
Have either of you looked at the Sweep example in the IDE ?

It does not move as fast as possible but it will get you started and let you experiment with the servo to make sure that it is wired correctly.  Once you know that it works then making the servo move directly from 0 to 180 is trivial, as is adding a wait at 180 degrees using either a simple but limiting method or a slightly more complicated but more flexible method.

Feel free to post your programs here even if they don't work as required but please include a description of what they should  do, what they actually do and/or any error messages.
219  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 04, 2014, 09:57:51 am
Quote
Don't you think it would be better to reassemble them in the correct order?

Exactly right, Paul, which is why I think the union approach is easier to understand, less error prone, and more portable.
Each to his own, but I can't see that the union approach is easier.  Although it removes the need to take the endian order into account when referring to the int in the union don't you still have to use the correct array index to refer to the high and low bytes individually ?
220  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 03, 2014, 11:36:33 am
Here is the code I have. I added the word function, which from the documentation should be written correctly, but it only outputs 0, nothing happens.

Code:
....
    EEPROM.write(10, word(myHigh, myLow));
 ....
EEPROM.write() writes a single byte to a single location.
You could use
Code:
    EEPROM.write(10,myHigh);
    EEPROM.write(11, myLow);
to write to successive locations then read back the 2 bytes and combine them using word()
221  Using Arduino / Programming Questions / Re: Writing potentiometer value to EEPROM over 255 on: August 03, 2014, 08:44:05 am
This should give you an idea of how to do it.
Code:
void setup()
{
  Serial.begin(115200);
  int myInt = analogRead(A0);
  byte myHigh = highByte(myInt);
  byte myLow = lowByte(myInt);
  Serial.println(myLow);
  Serial.println(myHigh);
}

void loop()
{
}
222  Using Arduino / Programming Questions / Re: TFT bar graph on: August 03, 2014, 05:39:49 am
What library are you using ?  I would expect it to provide functions to draw primitive shapes such as lines and circles and to turn blocks of pixels on and off.  In the case of a bar graph, turning on a block of pixels would to equivalent to turning on an LED but you will be able to get much finer resolution using the TFT display.
223  Using Arduino / Programming Questions / Re: TFT bar graph on: August 03, 2014, 05:17:21 am
What have you managed to do with the TFT so far ?
Can you set and unset pixels on it, or maybe turn a block of pixels on and off ?
224  Using Arduino / Programming Questions / Re: arduino code not working???? I am newbie at arduino programming on: August 03, 2014, 05:13:27 am
Quote
it is not working
Can you describe what it is doing ?

Put some Serial.prints into your program so that you know which parts of it are being executed and what the values of essential variables are at various points.

Read up on the LCD library.  Could you perhaps use the lcd.clear() method instead of your function to do the same thing, for instance ?
225  Using Arduino / Programming Questions / Re: arducopter althold on: August 03, 2014, 04:25:45 am
Some guesses and inferences from the context

what is  p_thr_alt_p (actually p - thr_alt_p) doing?
Calculates the error between the p value for the altitude and the target altitude

what is limit 250 mean?
Limits the value calculated above to 250

what is limit 0.5g to 1.5g  mean?
Limits the rate of change to between 0.5G and .5G

what is earth to body frame translation mean?
Don't know

what is limit throttle_max mean?
Limits the maximum throttle applied to accomplish the change in altitude


Do some reading on PIDs if you haven't already.
Pages: 1 ... 13 14 [15] 16 17 ... 289