Show Posts
Pages: 1 2 3 [4] 5 6 ... 25
46  Using Arduino / Programming Questions / Re: Arduino Light Meter, using RTC and an SD data logging script, help! on: February 03, 2014, 03:45:54 pm
The IDE should list the path to your sketchbook folder (file -> preferences). In this folder you need another folder named libraries and you place your libraries in there. Still in their folders.

ie; on my machine (a Linux box) sketchbook is in my root folder so the path to the Time library looks like

~/sketchbook/libraries/Time/

The Time lib files are in that Time folder.

Generally to install a downloaded user lib you simply need to uncompress it into the /sketchbook/libraries folder. Then restart the IDE.
47  Using Arduino / Programming Questions / Re: Arduino Light Meter, using RTC and an SD data logging script, help! on: February 03, 2014, 01:07:14 pm
Have you installed Time.h?
48  Using Arduino / Programming Questions / Re: Multiple Blinking LEDS at different intervals. on: February 01, 2014, 10:13:38 am
Oh well if we're showing code, here's some.

Code:
class myLED {
    byte _pin;
    boolean _state;
  public :
    // nothing happens in constructor
    myLED() {};
    // begin() called during setup();
    void begin(byte pin)
    {
      _pin = pin;
      _state = false;
      pinMode(_pin, OUTPUT);
      digitalWrite(_pin, LOW);
    };
    // run() called each loop();
    void run(unsigned long onMillis, unsigned long offMillis)
    {
      static unsigned long startMillis = 0;
      unsigned long currentMillis = millis();
      if (currentMillis - startMillis >= (_state ? onMillis : offMillis))
      {
        startMillis = currentMillis;
        _state = !_state;
        digitalWrite(_pin, (_state ? HIGH : LOW));
      }
    };
};

As a learning exercise I spent about a week of evenings blinking LEDs. I ended up with a lot of LED blinking code. This is just a class. Using it in a sketch I'd leave up to you.
49  Using Arduino / Programming Questions / Re: Multiple Blinking LEDS at different intervals. on: February 01, 2014, 12:19:22 am
Seeing as all three objects have the same basic behaviour I'd approach it with some class.

... and it would look a lot like blink without delay()
50  Using Arduino / Programming Questions / Re: Printing elements from an array? on: January 31, 2014, 10:26:50 pm
Quote
For instance, is there a command that would let me substitute the "100" value for "101"?

strcpy(products[0][2], "101");                         

It has to fit. Your strings have various lengths. If you change the "101" to "101.0" it will break in this case.

Are you really storing numbers as strings? Computers have better ways to store numbers.

http://www.cplusplus.com/reference/cstring/strcpy/
51  Using Arduino / Programming Questions / Re: Printing elements from an array? on: January 31, 2014, 07:24:02 pm
You print all that text and a line feed every time.
52  Using Arduino / Programming Questions / Re: invalid conversion from 'int*' to 'int' on: January 31, 2014, 02:28:58 pm
The name of an array is a pointer. So you tried to place a pointer in an array that was expecting an int. There are ways to do it but I don't think you need to.

Your randomness is basically a coin toss. Heads the LED or speaker is on, tails it isn't. So as you go through loop() toss a coin and decide whether you want the LED on and then do the same with the speaker. This will make the combination of the two random enough.

How you wish to toss the coin is up to you. Generate a random 0 or 1 or generate a random in a larger range and check whether it is odd or even. Whatever makes you feel good.

53  Using Arduino / Programming Questions / Re: see if condition its true for 2 minutes? on: January 25, 2014, 11:37:27 am
It's the mysterious condition x.
54  Using Arduino / Programming Questions / Re: see if condition its true for 2 minutes? on: January 25, 2014, 11:27:49 am
All the variables dealing with millis() need to be unsigned long.

I think the logic you might be looking for is:

if ( (condition == true) && (currentMillis - whenConditionWentTrueMillis >= twoMinutesinMillis) ) { it happened }

If you haven't got a good grasp of blink without delay you should do that first.

Also http://arduino.cc/en/Reference/If
55  Using Arduino / Programming Questions / Re: Odd error initializing array - any ideas? on: January 24, 2014, 07:19:58 pm
That would coincide with what I just found. Your method used less flash but more ram.

I used these two sketches. I think I translated your approach correctly. It took some looking, turns out it wasn't a big change. I did skip the sizeof() bits.

Sketch 1
Code:
const byte RPM_COUNT = 5;
const unsigned long RPMS[RPM_COUNT] = { 300000, 150000, 75000, 37500, 18750 };

class myClass{
    unsigned long rpmSpeed[RPM_COUNT];

public :

    myClass(void) { for (byte i = 0; i < RPM_COUNT; i++) rpmSpeed[i] = RPMS[i]; }
};

myClass object;
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Sketch 1 compile results:
Sketch uses 624 bytes (1%) of program storage space. Maximum is 32,256 bytes.
Global variables use 29 bytes (1%) of dynamic memory, leaving 2,019 bytes for local variables. Maximum is 2,048 bytes.

Sketch 2
Code:
const byte RPM_COUNT = 5;
const unsigned long RPMS[RPM_COUNT] = { 300000, 150000, 75000, 37500, 18750 };

class myClass {
    unsigned long rpmSpeed[RPM_COUNT];

  public :

    myClass(void) { memcpy(rpmSpeed, RPMS, RPM_COUNT); }
};

myClass object;
void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Sketch 2 compile results:
Sketch uses 542 bytes (1%) of program storage space. Maximum is 32,256 bytes.
Global variables use 49 bytes (2%) of dynamic memory, leaving 1,999 bytes for local variables. Maximum is 2,048 bytes.

I wonder why the extra 20 bytes?

So I changed the array size to 10 (and 100) and they both use the same ram. Flash use with memcpy() was still lower.

memcpy() wins except maybe for smaller arrays.  

By the way, thanks.
56  Using Arduino / Programming Questions / Re: Odd error initializing array - any ideas? on: January 24, 2014, 06:19:48 pm
Why would that be a better approach?

I'm going to go play with it in the mean time.
57  Using Arduino / Programming Questions / Re: Odd error initializing array - any ideas? on: January 24, 2014, 05:58:46 pm
So? What would be the best way to do this?

My first thought is to declare an array of constants in the header just before the class. Then assigning those values in the constructor.

Code:
const byte RPM_COUNT = 5;
const unsigned long RPMS[RPM_COUNT] = { 300000, 150000, 75000, 37500, 18750 };

class myClass{
    unsigned long rpmSpeed[RPM_COUNT];

public :

    myClass(void) { for (byte i = 0; i < RPM_COUNT; i++) rpmSpeed[i] = RPMS[i]; }
};


Is that a good approach or are there better ways?
58  Using Arduino / Programming Questions / Re: Turn pin HIGH for 1 minute without delay() on: January 21, 2014, 11:16:44 am
It doesn't really matter where in your code you write the pin HIGH just that you get the time that it happened. So that you can calculate when the desired interval has passed.

if (CurrentMillis - StartMillis >= IntervalMillis) is true, you're done turn it off.
59  Using Arduino / Programming Questions / Re: wind speed average on: January 17, 2014, 03:23:25 pm
I know.  smiley-grin

Thought I'd see if he figured that out and ask why.
60  Using Arduino / Programming Questions / Re: wind speed average on: January 17, 2014, 10:53:25 am
I took your code and added a way to store and average the last ten readings. I used your code hoping it would help you see what I did. Your code uses way too many floats. I'd store the actual analog readings which are an int and convert to a float when averaging and printing. It's best to minimize the use of floats where possible and with a little thought it's usually possible.

This basically uses the concept found in blink without delay for the timing of taking samples.

Code:
const int SENSOR_PIN = A0;
const int SAMPLE_COUNT = 10;
const unsigned long SAMPLE_RATE = 2000UL; // every two seconds

// array to store the samples
float sample[SAMPLE_COUNT];
byte sampleIndex = 0;

// function to average the samples
float sampleAverage(void)
{
  float accumulator = 0;
  for (int i = 0; i < SAMPLE_COUNT; i++)
  {
    accumulator += sample[i];
  }
  return accumulator / SAMPLE_COUNT;
}

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  static unsigned long lastSampleTime = 0;
  unsigned long currentTime = millis();

  // check if time for new reading
  if (currentTime - lastSampleTime >= SAMPLE_RATE)
  {
    lastSampleTime = currentTime;
    int sensorValue = analogRead(SENSOR_PIN);
    float voltage = sensorValue * (5.0 / 1023.0);
    Serial.print("voltage: ");
    Serial.println(voltage);
    // add the newest reading at the oldest pointer
    sample[sampleIndex] = voltage;
    // advance to next index which is now oldest
    sampleIndex++;
    // check for and handle rollover
    if (sampleIndex == SAMPLE_COUNT)
    {
      sampleIndex = 0;
    }
    // the sample array now contains the last ten readings
    // sampleIndex now points to the oldest reading
    // it will be replaced with the newest next time

    float average = sampleAverage();
    Serial.print("average:");
    Serial.println(average);
    float Wind_Speed = (6 * average);
    Serial.print("Wind_Speed:");
    Serial.print(Wind_Speed);
    Serial.println("m/s");
    float Wind_Kmph = 3.6 * Wind_Speed;
    Serial.print("Wind_Kmph:");
    Serial.print(Wind_Kmph);
    Serial.println("KMPH");
    Serial.println(".................");
  }
}


Hope this helps.
Pages: 1 2 3 [4] 5 6 ... 25