Hi, I have googled for good part of day but i am unable to find my desired solution. All i want to do is add 1 after every 2 seconds (time driven by millis not delays)
Problem is after 2000ms additions continiually happens 1,2,3,4... non stop
instead of once per 2 seconds
int i;
unsigned long previoustime;
void setup() {
Serial.begin(9600);
}
void loop() {
unsigned long currenttime = millis();
if (currenttime - previoustime >= 2000) {
++i;
previoustime = currenttime;
}
Serial.print("i");
Serial.println(i);
}
I assume by this you mean you edited your original post. You should never do that
unless for something that does not change you code. I makes UKHeliBob appear
to not be able to read simple code. Not nice.
ok, its working now, i dont know what caused the error as i was also using previoustime-currenttime before
So, you took UKHeliBob's advice, changed your code, it started working, and you don't know what the error was?
Amazing.
boolrules:
I assume by this you mean you edited your original post. You should never do that
unless for something that does not change you code. I makes UKHeliBob appear
to not be able to read simple code. Not nice.
So, you took UKHeliBob's advice, changed your code, it started working, and you don't know what the error was?
Amazing.
I apologize, it was never my intention, (perhaps lack of experience on forums).
As i said i was adding previoustime = currenttime, Afterwards I tried to recreate the problem but magically everything appears to be working and made me think that i may not have tried enough, as i dont want to waste good people time helping here on forums.