Millis() counter inside a loop
in
Programming Questions
•
1 month ago
Greetings all!
I am having a bit of a difficult time grasping Millis();
I understand with the example mentioned below how Millis() is implemented in a sketch. I am also aware that Millis begins the minute your sketch launches, so I attempted to implement a counter vairable that everytime the condition is met, the "counter" adds a 1. Problem is counter prints only a "0". code below:
- int iDatum;
- int counter;
- void setup() {
- //choose a point 5,000 milliseconds in the future
- iDatum=millis()+1000;
- timeSinceLastLetter = millis();
- ellipse(width/2, height/2, 10, 10);
- }
- void draw() {
- //is it now time?
- if (millis()>=iDatum) {
- ellipse(random(width), random(height), 10, 10);
- //choose another point 5 seconds hence...
- iDatum=millis() + 1000;
- counter = counter+1;
- }
1