NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » For command
March 24, 2011 by hariharan ![]() |
i wanted to use the for() command to increment the variable int i;
I want the variable "i" to increment with a particular time interval. how do i do it? |
---|---|
March 24, 2011 by bretm ![]() |
The best answer really depends on why you want to do that. I could tell you to do
but that might not be the best way, depending on your application. |
March 24, 2011 by Ralphxyz ![]() |
Well here is a unqualified (non programmer) answer. I am sure others will do better but here is a literal answer:
I believe that will work, of course the LCD write is sudo. Others will jump all over me if I am incorrect. Ralph |
March 24, 2011 by hariharan ![]() |
i want to do this so i can show time on my lcd |
March 24, 2011 by hariharan ![]() |
will this code work for a clock?
|
March 25, 2011 by hevans (NerdKits Staff) ![]() |
Hi Hari, Ralph gave you some great pointers up above, I suggest you take a close look at what he posted for you. The place where you are adding 1 does not really make sense. If you want a for loop to start from 1, simply make it start there by using the initialization parameter. The loop
would start at 1 and keep looping while i is less than 100. Your code would also not do what you really expect it to because of the way you laid out the for loops. Your first for loop will actually delay you one second, but then the next one will wait for full minute before the loop exists, and the next one would wait a full hour, the last one would not even really work because you would overflow the capacity of the delay function. It is a very good attempt at coding, and you should definitely take a second to understand why the way you laid out the flow does not work. I highly recommend you take a look at our crystal real time clock tutorial for an idea of how we kept track of "real time" Humberto |
March 26, 2011 by hariharan ![]() |
Thanks Humberto! But i do not understand the code written forn the crystal time clock I do not understand how u set up the interrupt. |
March 26, 2011 by Ralphxyz ![]() |
hariharan, start a new thread "How do you setup a interrupt". We have not had a detailed discussion on interrupts for a while (there are lots of discussions in the forum). It might be good to get a consolidated starting from scratch discussion going. Start with what you know, do some searching and make a attempt then post what you have. Ralph |
Please log in to post a reply.
Did you know that a flyback diode is important when driving a motor or any inductive load? Learn more...
|