Pages: [1]   Go Down
Author Topic: Does anyone have a simple stopwatch program  (Read 389 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found this one but I wanted it to have milliseconds
Code:
int ledPin = 8;

int clock = 998;

int hour = 10;
int min = 27;
int sec = 0;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  delay(clock);

  sec = sec + 1;

  // basic conditionals
  if (sec <= 20) {
    digitalWrite(ledPin, HIGH);
  }

  if (sec > 20) {
    digitalWrite(ledPin, LOW);
  }

  /* if (min > 20 && min < 40) {
    digitalWrite(ledPin, HIGH);
  } else {
     digitalWrite(ledPin, LOW);
  } */

  // time keeping stuff
  if (sec > 59) {
    sec = 0;
    min = min + 1;
  }

  if (min > 59) {
    min = 0;
    hour = hour + 1;
  }

  if (hour > 23) {
    hour = 0;
  }

  Serial.print(hour);
  Serial.print(":");
  Serial.print(min);
  Serial.print(":");
  Serial.print(sec);
  Serial.print("n");
}
Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I wanted it to have milliseconds
At 9600 baud, it takes over one millisecond to transmit just one character.
Be careful   smiley-wink
« Last Edit: May 11, 2010, 01:57:39 am by GrooveFlotilla » Logged

Per Arduino ad Astra

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

why do you say be careful? Also what about the serial print not showing the real time millis and just displaying it when paused...would that help any?
Logged

Pages: [1]   Go Up
Jump to: