Stop watch


hi friends,

 i tried male stop watch arduino uno, lcd , 2 push button switches.the project successful.now make timer can count time interval between 2 events change of state.its not done momentarily push button. please see attached code , please provide corrections

state 1- pin low high :start mills
state 2- pin high low :stop mills

time elapsed = stop mills - start mills

i trying implement interrupt on pin 1 , 2 of uno.i unable make success,kind attention required 

thanks , regards

why want use interrupts? kind of timing talking about?

and should not use serial.print in interrupts.

next time, please post small code in post using code tags
type [code]
paste code after that
type [/code]

the result (to save other people download)
code: [select]

unsigned long start, finished, elapsed;
void setup()
{
  serial.begin(9600);

  attachinterrupt(0, displayresult , change); // start button
  attachinterrupt(1, displayresult , change); // stop button

  serial.println("press 1 start/reset, 2 elapsed time");
}
void displayresult()
{
  float h, m, s, ms;
  unsigned long over;
  elapsed = finished - start;
  h = int(elapsed / 3600000);
  on = elapsed % 3600000;
  m = int(over / 60000);
  on = on % 60000;
  s = int(over / 1000);
  ms = on % 1000;
  serial.print("raw elapsed time: ");
  serial.println(elapsed);
  serial.print("elapsed time: ");
  serial.print(h, 0);
  serial.print("h ");
  serial.print(m, 0);
  serial.print("m ");
  serial.print(s, 0);
  serial.print("s ");
  serial.print(ms, 0);
  serial.println("ms");
  serial.println();
}
void loop()

{


  attachinterrupt(0, displayresult , change); // start button

  start = micros();

  attachinterrupt(1, displayresult , change); // stop button
  finished = micros();


  displayresult();
}


Arduino Forum > Using Arduino > Programming Questions > Stop watch


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'