i want to print seconds on lcd from 0 to 30 using millis function how can i do that please help me guys
Basically....
If start millis minus the current millis is greater than or equal to 1000, add one to seconds. And set start millis to equal current millis. Display seconds on the LCD. And if the seconds are now at 30, reset seconds back to 0.
Not extremely accurate in terms of time keeping. But I doubt you'll notice being off by a few milli after 30 seconds.
sir can you please give me a demo code i am totally a begginer
Azhar
read on Millis()
make it print the time every time millis is called and then I help you with the rest.
I think we are mostly here to help not to do it for you.
int Second;
int S;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int startmillis=millis();
int currentmillis=0;
if(startmillis-currentmillis>=1000){
startmillis=currentmillis;
Serial.print(Second);
Second=S+1;
}
}
some thing like that ???
Azhar:
sir can you please give me a demo code i am totally a begginer
See this post (Using millis for timeing. A beginners guide)for a demo. There are others too. Such as Blink without delay.
Azhar:
int Second;
int S;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}void loop() {
// put your main code here, to run repeatedly:
int startmillis=millis();
int currentmillis=0;
if(startmillis-currentmillis>=1000){startmillis=currentmillis;
Serial.print(Second);
Second=S+1;
}}
some thing like that ???
Pretty decent first attempt. When using milli, the numbers are quite large. So, you'll want to use "unsigned long" instead of "int" for your start and current. And move startmillis and current millis prior to setup.
Edit. You could leave current millis where it is.
thx sir iam done with that
And if you want it to reset to 0 after 30 seconds, you'll need another if statement at the end doing that.
Whats wrong with calculating it:
Second = (millis() - startmillis) / 1000ul ;
Much simpler, very hard to have obscure bugs in a simple formula!