About Here

This web blog is established for collecting useful information about building prototype with arduino or other applications. This page shuld help a designer with very basical technical cognition to build a working model or a prototyp for his design concept. We find prototyp or working model an excellent tool to test concept and understand it's usage in real condition (not only fantasy in mind). It's ofter very hard to realize every functions of a design concept. However it's our goal here to make this task easier.

What should be always keeped in mind is that we are not engineers and it's not our goal to design a perfect electron programme control. We are designers who are more willing to understand the users through prototype testing.

This web-site is still under construction and more information shall be collected. :)

Oct 24, 2011

How to count time in Arduino

There are two simple ways to do pretty exact time counting in Arduino. The first one is to use delay(). Everytime it runs a delay(1), it's 1 millisecond passed. (1millisecond =0.001second, which means to delay 1 second you need to run delay(1000). ) Like this, you can count the runnning time by counting the delayed milliseconds.

But you may have many defferent delay() in your loop codes and you don't know how many milliseconds have been delayed anymore because it runs everytime differently. In this case you will need to use millis(). It's an internal clock in Arduino which starts to count time everytime the Arduino board starts running or is reseted. It can be counted to 50 days. To give the data of millis() to a variable you have to define this variable as unsigned long.

Code Example
unsigned long Val;
void setup(){
  Serial.begin(9600);
}
void loop(){
  Val = millis();
  Serial.print("Count = "); Serial.println(Val);
  delay(1000);
}

Reference:
http://arduino.cc/en/Reference/Millis

No comments:

Post a Comment