Go Down

Topic: Does anyone have a simple stopwatch program (Read 421 times) previous topic - next topic

tubular

I found this one but I wanted it to have milliseconds
Code: [Select]
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");
}

Groove

#1
May 11, 2010, 08:56 am Last Edit: May 11, 2010, 08:57 am by GrooveFlotilla Reason: 1
Quote
I wanted it to have milliseconds

At 9600 baud, it takes over one millisecond to transmit just one character.
Be careful   ;)
Per Arduino ad Astra

tubular

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?

Go Up