Timer and Button
              in 
             Programming Questions 
              •  
              1 year ago    
            
 
           
             I hope someone can help me.
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
                    
             
             
              
             
             
                 
             
             
              
             
             
                   
             
             
              
             
             
                
             
             
                
             
              
           
 
            
           
             I cannot solve this problem: I have to create a sketch with a button. When I click on the button, I have to put in the window, the time that has elapsed since the sketch started. Every time the button is pressed a new time is posted, but the time doesn’t change until the button is pressed.
            
            
             This is my code. 
            
            
             Thanks!
            
            
              int x = 300;
             
             
              int y = 600;
             
             
              float timer;
             
             
              float setupTime;
             
             
              PFont font;
             
             
              void setup() {
             
             
                background(204);
             
             
                size(600,600);
             
             
                ellipseMode(RADIUS);
             
             
                smooth();
             
             
                font = loadFont ("ArialMT-48.vlw");
             
             
                textFont (font);
             
             
                 setupTime=millis();
             
             
              }
             
             
              void draw() {
             
             
                 background(204);
             
             
                 textSize(16);
             
             
                    fill(255);
             
             
                    ellipse(x, y, 50, 30);
             
             
                    fill(0);
             
             
                    text("COUNT", 275, 595);
             
             
                    fill(0);
             
             
                    println(millis()-setupTime);
             
             
                    timer=(millis()-setupTime); 
             
             
              }
             
             
                 void mouseClicked()  {
             
             
                 setupTime=millis();
             
             
                 text(timer, 300, 40);
             
             
              }
             
             
              
              1  
            
 
            