// objet global Chrono, déclaration de classe StopChronoTimer sc; // Communication avec Arduino import processing.serial.*; Serial myPort; // Create object from Serial class static String val; // Data received from the serial port int btnVal = 0; void setup() { size(800, 600); println (millis()); sc = new StopChronoTimer(); sc.start(); String portName = "COM3";//à changer selon config matériel myPort = new Serial(this, portName, 9600); } void draw() { top(); } /// FONCTIONS void top() { // dessine le texte-temps sur l'écran background(220); fill(000); textSize(128); textAlign(CENTER); // nf est utile pour transformer des chiffres en string text https://processing.org/reference/nf_.html text(nf(sc.heures(), 2)+":"+nf(sc.minutes(), 2)+":"+nf(sc.secondes(), 2), width/2,height/2); } // CLASSES class StopChronoTimer { int startTime = 0; int stopTime = 0; boolean running = false; void start() { startTime = millis(); running = true; } void stop() { stopTime = millis(); running = false; } int gTempsPasse() { int tempsP; if (running) { tempsP = (millis()-startTime); } else { tempsP =(stopTime - startTime); } return tempsP; } int secondes() { return (gTempsPasse()/1000) % 60; } int minutes() { return (gTempsPasse()/(1000*60)) % 60; } int heures() { return (gTempsPasse()/(1000*60*60)) % 24; } }