Stopwatch class

Hi

I would like to use the StopWatch class library http://playground.arduino.cc/Code/StopWatchClass#.UymLg_l_uto
in Arduino 1.0.5 .

I have created the StopWatch.c and StopWatch.h files and added them to the library .
After adding the header file , I get the following error :

In file included from C:\Program Files (x86)\Arduino\libraries\StopWatch\StopWatch.c:20:
C:\Program Files (x86)\Arduino\libraries\StopWatch\/StopWatch.h:22: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'StopWatch'
C:\Program Files (x86)\Arduino\libraries\StopWatch\StopWatch.c:23: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
C:\Program Files (x86)\Arduino\libraries\StopWatch\StopWatch.c:43: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
C:\Program Files (x86)\Arduino\libraries\StopWatch\StopWatch.c:49: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
C:\Program Files (x86)\Arduino\libraries\StopWatch\StopWatch.c:60: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
C:\Program Files (x86)\Arduino\libraries\StopWatch\StopWatch.c:66: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
C:\Program Files (x86)\Arduino\libraries\StopWatch\StopWatch.c:75: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'StopWatch'
C:\Program Files (x86)\Arduino\libraries\StopWatch\StopWatch.c:80: error: expected identifier or '(' before ':' token

Please tell me what to do .

I have created the StopWatch.c and StopWatch.h files and added them to the library

Rename StopWatch.c to StopWatch.cpp

Close and re-open the IDE and try again

Hi Many thanks for helping me out . Appreciate it .

Regards

Hi I have an error when I add in the below line to my code . StopWatch sw_micros(StopWatch::MICROS);

Read_Sector_and_send_over_i2c_with_Sector_speed:23: error: 'StopWatch' does not name a type
Read_Sector_and_send_over_i2c_with_Sector_speed.ino: In function 'void loop()':
Read_Sector_and_send_over_i2c_with_Sector_speed:57: error: 'sw_micros' was not declared in this scope

Am I not calling it correctly ? I see the same line is used in the example as well.

please post your whole sketch so we can reproduce the problem

Where (exactly) have you installed the StopWatch library ?

Hi
I have installed the library at
C:\Program Files (x86)\Arduino\libraries\StopWatch

and please find my code below .

//Arduino master device

#include <Wire.h>
#include <StopWatch.h>


int sectorFromHall(int hall1, int hall2, int hall3);
int rawHall1 =0 ;
int rawHall2=0;
int rawHall3 = 0;

int h1=3;
int h2=4;
int h3=5;
int previousSector = 6;
int hallSector = 6;
float MotorSpeed = 0;

StopWatch sw_micros(StopWatch::MICROS);
//StopWatch sw_micros;

void setup()
{
 Serial.begin(38400);
 pinMode(h1, INPUT); 
 pinMode(h2, INPUT); 
 pinMode(h3, INPUT); 
 
 digitalWrite(h1, HIGH);
 digitalWrite(h2, HIGH);
 digitalWrite(h3, HIGH);
 

  Wire.begin(); // join i2c bus (address optional for master)
  hallSector = sectorFromHall(rawHall1, rawHall2, rawHall3); 

  delay(500);
   Wire.beginTransmission(80); // transmit to slave device F2837   #0x50 (decimal is 80)
   Wire.write(hallSector);             
   Wire.endTransmission();    // stop transmitting    
}



void loop()
{
  previousSector = hallSector;
  //Serial.println("HI !");
  rawHall1=digitalRead(h1);
  rawHall2=digitalRead(h2);
  rawHall3=digitalRead(h3);
  
sw_micros.start();

  hallSector = sectorFromHall(rawHall1, rawHall2, rawHall3);
//  Serial.println(hallSector);
  
 
 if(previousSector != hallSector){

    sw_micros.stop();
    sw_micros.value();




    Wire.beginTransmission(80); // transmit to slave device F2837   #0x50 (decimal is 80)
    Wire.write(hallSector);             
    Wire.endTransmission();    // stop transmitting   
         
    MotorSpeed = (10.0 /sw_micros.value()) ;        
    Serial.println(MotorSpeed);     
    sw_micros.reset();        
                                            
    }
}


int sectorFromHall(int hall1, int hall2, int hall3)
{
	int sector;

	if ((hall1 == 0) && (hall2 == 1) && (hall3 == 1))
	{ 
		sector = 0;

	}
	else if ((hall1 == 0) && (hall2 == 1) && (hall3 == 0))
	{
		sector = 1;

	}
	else if ((hall1 == 1) && (hall2 == 1) && (hall3 == 0))
	{
		sector = 2;

	}
	else if ((hall1 == 1) && (hall2 == 0) && (hall3 == 0))
	{
		sector = 3;

	}
	else if ((hall1 == 1) && (hall2 == 0) && (hall3 == 1))
	{
		sector = 4;

	}
	else if ((hall1 == 0) && (hall2 == 0) && (hall3 == 1))
	{
		sector = 5;

	}

	else
	{sector = 6;
        }
	return sector;
}

Please tell me the changes I have to make .

Kind Regards

Please tell me the changes I have to make .

I created a StopWatch folder in my libraries folder, in my sketch directory. I copied and pasted the header file code into Notepad++, and saved it as StopWatch.h in the StopWatch folder. I repeated the process to create StopWatch.cpp.

I opened the IDE, and copied and pasted your sketch. I got one "error":

Binary sketch size: 7,084 bytes (of a 30,720 byte maximum)

Hi Paul , I have done as you have said and now it works just as you said. Many Thanks

anishh2003: Hi I have installed the library at C:\Program Files (x86)\Arduino\libraries\StopWatch

Please tell me the changes I have to make .

Kind Regards

Paul has given you the answer and you have now got your program working, but now you will see why I asked exactly where the library was installed.

Hi, Help on installing libraries HERE:

And many useful Libraries as well as Stopwatch, HERE: from Rob Tillaart!