Show Posts
Pages: 1 [2] 3 4 ... 7
16  Using Arduino / Programming Questions / Re: Class constructor not executing on: August 08, 2011, 08:52:26 pm
Some information here.

Short answer, "Don't do that". You can't rely on any of the hardware being setup properly before constructors for global objects are called. Rework your class with a begin() or init() member function that does the initialisation, and call it in setup().
17  Using Arduino / Programming Questions / Re: millis() overflow -- what happens??? on: August 03, 2011, 09:33:31 pm
... Arduino reference docs that still talk about the 'roll over' interval, etc the subject still comes up from time to time. Probably an indication that the subject and proven solution should be made either a stick or included in the 'official' Arduino reference for the millis() function.

Totally OT, but I have the same uneasy feeling about the use of delay(). The number of posts where an OP is looking for a solution to "doing two things at once" is very high. I wonder whether the use of delay() should be discouraged. I would go so far as to suggest delay() should be considered an advanced technique on par with goto.

Perhaps the subject of a separate thread...
18  Using Arduino / Programming Questions / Re: millis() overflow -- what happens??? on: August 03, 2011, 07:38:27 pm
There was a 'famous' posting here in the past explaining how the subtraction overflow bit handles the roll over condition just fine as long as you use subtraction for your time interval test calculation.

If this is the post you're referring to, then I'll take that as high praise indeed.

19  Using Arduino / Programming Questions / Re: Programming tomb!!! on: July 31, 2011, 10:43:43 pm
Quote
pow() returns a float.  Arduino is MUCH happier with integers

Agreed, but I set myself the goal of trying to do it in one line (not counting the #include).
20  Using Arduino / Programming Questions / Re: Programming tomb!!! on: July 31, 2011, 08:22:33 pm
I don't have my Arduino here so I can't test, but it works fine on Linux using int as long and short as int. Must be an Arduino integer or math library issue.

You will need to split the functionality up and see at what point it is failing:

Code:
int getDigit(long number, int place)
{
    double p = pow(10, place - 1);
    long l = long(p);
    long n = number / l;
    long m = n % 10;

    // Debug output
    Serial.print("getDigit() called, number = ");
    Serial.print(number);
    Serial.print(", place = ");
    Serial.print(place);
    Serial.print(", l = ");
    Serial.print(l);
    Serial.print(", n = ");
    Serial.print(n);
    Serial.print(", m = ");
    Serial.println(m);

    return int(m);
}
21  Using Arduino / Programming Questions / Re: Programming tomb!!! on: July 31, 2011, 07:28:54 pm
How about:

Code:
#include <math.h>

int getDigit(long number, int place)
{
    return ((number / long(pow(10, place - 1))) % 10);
}
22  Using Arduino / Programming Questions / Re: While loop questions. on: July 06, 2011, 08:43:30 pm
Quote
A more interesting programming problem (and, maybe a more elegant and better-behaved machine) might be to distribute the moves as equally as possible between the two motors.  A recent thread mentioned one possible approach, but I haven't tried it.  (I think I could brute-force it with simple integer arithmetic rather than lisp-like lists, but...)

Bresenham's Line Algorithm will do the work for you. http://en.wikipedia.org/wiki/Bresenham's_line_algorithm

In the Wikipedia article, make the x-axis the motor that has to move the furthest (motor 1), and y the other one (motor 2). Each time through the loop step Motor 1 and only step Motor 2 when you see "y = y + 1".
23  Using Arduino / Programming Questions / Re: The difference between #define and const on: July 03, 2011, 07:28:27 pm
Also it can result in different (and unexpected) behaviour. Consider the following (standard C++, not Arduino) code:

Code:
#include <iostream>
using namespace std;
#define a1 2
const float a2 = 2;
int main(int argc, char **argv)
{
    int b = 3;
    float f1 = b / a1;
    float f2 = b / a2;
    cout << "f1 (define-based) : " << f1 << endl;
    cout << "f2 (const float-based) : " << f2 << endl;
    return 0;
}

Apropos the calculation of f1, because a1 is considered an integer, the division is an integer division, so the result is calculated then converted to a float (result = 1). In the second case (calculation of f2), as a2 is defined as a float, the variable "b" is promoted to a float and the division is floating-point, resulting in the value of f2 being 1.5.

I realise this is a contrived example, and there are a number of ways around, including (float) in the define, or using 2.0 as the value rather than 2. The purpose is to show that behaviour is less predicable when you use #define.
24  Using Arduino / Programming Questions / Re: millis not accurate? on: June 19, 2011, 09:17:20 pm
Coding_Badly's solution (page 1) is the correct one.

Only read millis() once per loop. If you're reading millis() more than once in your calculation, chances are you are accumulating overrun.

The essential idea is to only keep track of when you last *should* have triggered, not when you last actually did, that way any overrun is ignored in the calculation of the time at which you next should trigger, and therefore doesn't accumulate. You can't avoid a certain amount of overrun on each trigger, the best you can do is avoid its accumulation.

Set your first trigger time in setup(), then in your loop check to see if the current time exceeds this by your delay amount (1000). If so, add your delay (1000) to the previous trigger time and do your required work. That's all:

Code:
unsigned long trigger;
unsigned long delay = 1000;

setup()
{
  trigger = millis();
}

loop()
{
  if ( (millis() - trigger) > delay )  // Optionally use "while" instead of "if"
  {
    // Do your stuff here.

    trigger += delay;
  }
}

By using subtraction in the comparison you can ensure that rollover is handled correctly (see http://arduino.cc/forum/index.php/topic,42997.msg311529.html#msg311529)

This method also has the benefit that it will "catch up" if the processing is delayed for some reason, because you are only adding 1 second to the trigger each time through the loop, eg. if there is a 10 second delay for some reason (perhaps a very slow print every 10 mins or so), millis() will be 10000 counts ahead of the value of "trigger" so the loop body will execute 10 times in a row quickly until "trigger" is eventually ahead of millis().
25  Topics / Device Hacking / Re: Wii motion + on: June 16, 2011, 09:46:31 pm
Quote
WM+ is technically an accelerometer for measuring x y z translation

Technically the WM+ has gyros, not linear accelerometers.

Quote
t can be used to measure tilt but requires some math,

Gyros measure rotational rate about an axis, so you need to add up the rates over time (ie. "integrate") to get the rotational distance (tilt from initial measurement). Gyros in that sense are "relative" devices and cannot determine which absolute position they are pointing at any time.

Quote
the nunchuck cuz it does contain gyro's to measure tilt

No, the nunchuk only contains linear accelerometers, the measurement of tilt is possible because of the way gravity resolves into the orthogonal axes along which the accelerometers are placed. As you tilt from horizontal some of the gravitational acceleration is measured on the accelerometer other than the vertical one, as calculated by trigonometry.
26  Development / Other Software Development / Re: Arduino Programming Environment for iPad on: March 09, 2011, 08:44:15 pm
Quote
That would arguably make it a "wireless telephone", but no mere functional change could make it a "handset".
Hmm, not sure
Quote
(Google)define: handset
Quote
•The part of a telephone, containing both receiver and transmitter (and sometimes dial), that is held in the hand
http://www.google.co.uk/search?hl=en&source=hp&biw=1276&bih=815&q=define%3A+handset&aq=f&aqi=g10&aql=&oq=&safe=vss
The iPad 2 has both a speaker and a microphone on a single unit - it contains both a receiver and transmitter so does that not make it a handset?

You & I may argue about this all week, and I may ultimately agree with you, however it seems to be a fair stretch (less than half of those definitions support your argument).

Regardless, in the end if you root your iPad2, Apple decides to sue you, and your defensive argument revolves around the above interpretation, you should expect Apple to argue vigorously in court that the iPad2 is *not* a mobile telephone handset.
27  Development / Other Software Development / Re: Arduino Programming Environment for iPad on: March 06, 2011, 05:30:22 pm
Quote
The ruling (http://www.copyright.gov/1201/, part (2)) is specific to "wireless telephone handsets", which the iPad is not. The press reported it incorrectly as "iPhones and other mobile devices", but it is narrower than that.
Well as the iPad also now has facetime, the new one at least could probably fit into that ruling.

That would arguably make it a "wireless telephone", but no mere functional change could make it a "handset".
28  Development / Other Software Development / Re: Arduino Programming Environment for iPad on: March 03, 2011, 09:48:35 pm
Quote
I do believe however that "Jail Breaking" or Rooting a device was found to be legal by courts here in the US and well within the scope and spirit of this community.

The ruling (http://www.copyright.gov/1201/, part (2)) is specific to "wireless telephone handsets", which the iPad is not. The press reported it incorrectly as "iPhones and other mobile devices", but it is narrower than that.
29  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Probable randomSeed() random() bug on: March 11, 2010, 06:11:55 am
I don't understand why you think that reseeding a PRNG before each call with a poorer RNG should produce a statistically good random sequence.

The PRNG is designed to produce a statistically random set of values when called repeatedly, only calling it once doesn't allow it do so. I suspect theoretically a PRNG could be created that passes Knuth's statistical test and yet guarantee to produce a "2" as the first output after being seeded with any value.

It reminds me of an old joke, a great PRNG if you only call it once:
Code:
int random()
{
  return 4; // Random number chosen by a fair die roll
}

Your results reflect primarily the lack of randomness in your seed selection. I'd be interested to see what the distribution of the seed values are, I'm not sure how random they are.
30  Forum 2005-2010 (read only) / Bugs & Suggestions / LCD Library on: April 23, 2008, 12:08:53 am
It looks like the original LCD library author misread the Serial Library's "println()" (print line) method as "printIn" (print in), and duplicated it (erroneously) in the LCD lib for consistency. The method name is repeated in the LCD4Bit library too, with the following acknowleged by the author (neillzero) in LCD4Bit.cpp:

Code:
//print the given string to the LCD at the current cursor position.  overwrites, doesn't insert.
//While I don't understand why this was named printIn (PRINT IN?) in the original LiquidCrystal library,
//I've preserved it here to maintain the interchangeability of the two libraries.
void LCD4Bit::printIn(char msg[]) {

IMHO it should be updated, as it is neither intuitive nor consistent in its current state.

Is there too much momentum to change it now?
Pages: 1 [2] 3 4 ... 7