Sunday, 15 November 2015

Arduino tutorial 3: millis() function

If you are new for my tutorial,just check out this

Things to know about ARDUINO

ARDUINO TUTORIAL 1: Reading analog sensor

Arduino tutorial 2:basic programmings

millis()
  • It is a inbuilt function of arduino(so we need not to include any preprocessor statement to use this).
  • If you use the millis() function,it gives the number of milliseconds since the arduino started running the sketch. so it is named as millis().
  • Delay() function is also an inbuilt function as like millis().If we invoke delay() function nothing will be happen untill delay() has finished.
  • So at that time ,the response from arduino would not instantaneous.It is a drawback
  • Some critical situation you may not use delay() function in your program.Instead of that you can use millis().
  • ()-represents that it is a function.
  • This function is also used to measure frequency using arduino,to find the toggle time and most importantly for deb-ounce. 

Serial monitor
  • On top right corner of the above image is a button for Serial monitor.
  • It displays the Serial data from arduino.
  • If you want to use this ,you want to begin this in setup().
  • Serial.begin(9600) is used to begin communication to Serial monitor.9600 is the baud rate which defines the rate of speed of data transfer.
  • Serial.print("Arduino program"),this command print "Arduino program".

millis() program:

  •  In above program,Serial communication to Serial monitor is invoked in setup().
  • In loop,Reasonable delay for better visibility. you can change the delay time and you get the corresponding output change.
  • Serial.println() -It print consecutive data in new line.Instead of this if you use Serial.print() ,the new line would not be invoked.
  • just run this on your arduino and see what it will do.
millis() counter for 10 sec:

This is to count 10 sec using millis() and It is little bit complicated than what we seen before.explanation is on image itself.


   
The output of this program is :







If you have any douts,feel free to ask me in comment box.
To get more updates like my page in facebook
Learn Electronics-Facebook

No comments:

Post a Comment