Pages: [1]   Go Down
Author Topic: need some help with this library  (Read 871 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im trying to install the stopwatch library from the arduino playground
http://playground.arduino.cc/Code/StopWatchClass
im confused on how to do it.. when i click on the get "get code" button it does not work..
so i decided to copy and paste with my text editor the .h and .cpp file
i created a folder in my arduino libraries folder named "StopWatch"  then saved the two files renaming them with the correct extension.  this does not appear to work.   what am i doing wrong?  im using a mac
thanks
matt
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1015
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can avoid using libraries.
Select the text with your mouse and copy paste them in files with the same name as in the library in your Arduino project.
The example code uses #include <StopWatch.h>, you have to change that into #include "StopWatch.h", because it is now a project file and not a library.
« Last Edit: January 19, 2013, 02:46:33 pm by Krodal » Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 109
Posts: 4074
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Exactly where did you put the StopWatch folder ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Exactly where did you put the StopWatch folder ?

documents/arduino/libraries/StopWatch
                                              StopWatch.h
                                              StopWatch.cpp

is the copy and paste with my text editor how im supposed to do it?

Logged

Offline Offline
Edison Member
*
Karma: 64
Posts: 2488
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you save the sample sketch as:     documents/arduino/StopWatch/StopWatch.ino
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Bradshaw106
Note that new libraries only work after closing all IDE's as they are read at the start.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just copied and pasted the example sketch.  I also restarted the IDE
I should mention, the reason I don't think my library is working is because when I try to verify the example sketch I get all kinds of errors..
For example.
Stopwatch not declared in this scope
Stopwatch does not name a type
Lots of errors, probably 15 or so I assumed it was because I didn't load the library correctly?  But it seams I did, I will try to debug the code and see what happens
Logged

Offline Offline
Edison Member
*
Karma: 9
Posts: 1015
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could make a screendump and crop that and post an image of the first error message.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here are the errors
sketch_jan19a:3: error: 'StopWatch' does not name a type
sketch_jan19a:4: error: 'StopWatch' does not name a type
sketch_jan19a.ino: In function 'void setup()':
sketch_jan19a:11: error: 'STOPWATCH_LIB_VERSION' was not declared in this scope
sketch_jan19a:13: error: 'SWarray' was not declared in this scope
sketch_jan19a.ino: In function 'void loop()':
sketch_jan19a:18: error: 'MySW' was not declared in this scope
sketch_jan19a:62: error: 'StopWatch' has not been declared
sketch_jan19a:65: error: 'StopWatch' has not been declared
sketch_jan19a:68: error: 'StopWatch' has not been declared
sketch_jan19a:78: error: 'SWarray' was not declared in this scope

here is the sample sketch
Code:
#include <StopWatch.h>

StopWatch MySW;
StopWatch SWarray[5];

void setup()
{
  Serial.begin(115200);
  Serial.println("Stopwatch demo");
  Serial.print("Version: ");
  Serial.println(STOPWATCH_LIB_VERSION);

  SWarray[0].start();
}

void loop()
{
  Serial.println(MySW.isRunning());
  delay(100);

  MySW.start();
  Serial.println(MySW.isRunning()); 
  Serial.println("START 1");
  for(int i=0; i<5; i++)
  {
    delay(10);
    Serial.println(MySW.elapsed());
  }

  MySW.stop();
  Serial.println(MySW.isRunning());
  Serial.println("STOP");
  for(int i=0; i<5; i++)
  {
    delay(10);
    Serial.println(MySW.elapsed());
  }

  MySW.start();
  Serial.println(MySW.isRunning());   
  Serial.println("START 2");
  for(int i=0; i<5; i++)
  {
    delay(10);
    Serial.println(MySW.elapsed());
  } 
  MySW.reset();
  Serial.println(MySW.isRunning());
  Serial.println("RESET");

  MySW.start();
  Serial.println(MySW.isRunning());
  Serial.println("START 3");
  for(int i=0; i<5; i++)
  {
    delay(10);
    Serial.println(MySW.elapsed());
  }

  switch(MySW.state())
  {
    case StopWatch::RESET:
      Serial.println("reset");  // e.g. disable stop/reset
      break;
    case StopWatch::RUNNING:
      Serial.println("running"); // display laptime
      break;
    case StopWatch::STOPPED:
      Serial.println("stopped"); // display finaltime
      break;
    default:
      Serial.println("unknown");
      break;
  }

  delay(3000);
  Serial.print(" >>>  laptime loop() : ");
  Serial.println(SWarray[0].elapsed()); 
}
/code]

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I copied the StopWatch.h code from the web site. I opened the Arduino IDE. I created a new tab, StopWatch.h, and pasted the code. I repeated the process for StopWatch.cpp. I pasted the example code in the .ino tab.

Because I am using a borrowed computer, I don't have all the libraries installed, so I deleted all the LiquidCrystal stuff from the sketch. I changed the <> in the StopWatch include statement to "".

Then, I clicked Verify (using 1.0.1). I got this "error" message:

Quote
Binary sketch size: 2,892 bytes (of a 32,256 byte maximum)
Hopefully, you'll be able to resolve that on your own.
Logged

Offline Offline
Edison Member
*
Karma: 64
Posts: 2488
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just did a copy and paste, created the 3 files and everything worked OK.
I did not change any code. I have Rev3 UNO, IDE 1.03 and Windows 7-64bit
I have:
C:\Users\YourName\Documents\Arduino\libraries\StopWatch\StopWatch.cpp
C:\Users\YourName\Documents\Arduino\libraries\StopWatch\StopWatch.h
C:\Users\YourName\Documents\Arduino\StopWatch\StopWatch.ino
Logged

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://flic.kr/p/dMXyLP
thats how to open a new tab
Logged

What is man's best friend? The breadboard!

Pages: [1]   Go Up
Jump to: