Sketch set-up - time of actions

Hello guys, i need to help to set a project. I’d like to know how can i write the code by Processing. I don’t understand to set a counter to make some operations.
I explain my project; there is a beamer will project a black screen with a string of carachters made with Processing, if the sharp sensor is triggered for 30 seconds i want to show just a black screen without the string of character. Is the sensor is triggered for 2 minutes, Processing will show an image.

I copy my sketch so you can see my project.

import codeanticode.syphon.*;

import processing.serial.*;

Serial myPort;  // Create object from Serial class
int val;      // Data received from the serial port

SyphonServer server;
float x = 0;
ArrayList<TEXTBOX> textboxes = new ArrayList<TEXTBOX>();

boolean send = false;
String msg = "";
String msg2 = "";

int pressed = 0;

Timer startTimer;

void setup() {
  size(1200, 700, P3D);
  printArray(Serial.list());
  String portName = Serial.list()[2];
  myPort = new Serial(this, portName, 115200);

  server = new SyphonServer(this, "Processing Syphon");
  startTimer = new Timer(10);

  InitLayout();
}


void draw() { 
  if ( myPort.available() > 0) {  // If data is available,
    val = myPort.read();         // read it and store it in val
  }

  if (val == 1) { // sensor triggered
    background(0);
    PFont f = createFont ("Georgia", 40);
    textFont(f);
    textSize(20);

    String s = " Try to sit in two chairs between a table ";
    text(s, 415, 100);
    String l = " Choose a shot of alcohol or juice, water or nothing too and stay in silence mode ";
    text(l, 232, 600);

    // start timer
    startTimer.countDown();
    if (startTimer.getTime() <= 0) {
      println("Do something");
    }
  } else {
    background(200);


    PFont f = createFont ("Georgia", 40);
    PFont z = createFont ("Georgia", 30);
    PFont d = createFont ("Georgia", 80);
    if (pressed !=1) {

      String c = "Try to write in the Text boxes the words ";
   // String s = " sit in two chairs between a table. They will get a shot of alcohol or juice, water or nothing too and ";

   //textFont(f);
     // textSize(20);
    //  text(s, 100, 100);


      textFont(d);
      textSize(20);
      text(c, 100, 400);
      color(20);

      for (TEXTBOX t : textboxes) {
        t.DRAW();
      }
    }
  }
  if (send) {
    text(msg, (width/2 - textWidth(msg)), 260);
    text(msg2, width/2, 260);
    startTimer.countDown();
    color(240);
    fill(0);
    text(startTimer.getTime(), width/2-40, 290);
  }
  server.sendScreen();
}

void InitLayout() {
  TEXTBOX receiver = new TEXTBOX();
  receiver.W = 500;
  receiver.H = 50;
  receiver.X = (width - receiver.W) / 13;
  receiver.Y = 200;


  textboxes.add(receiver);

  TEXTBOX message = new TEXTBOX((width - receiver.W) / 13, 265, 500, 50);
  textboxes.add(message);
}

void mousePressed() {
  for (TEXTBOX t : textboxes) {
    t.PRESSED(mouseX, mouseY);
  }
}

void keyPressed() {
  for (TEXTBOX t : textboxes) {
    if (t.KEYPRESSED(key, keyCode)) {
      send = true;
      msg = textboxes.get(0).Text + " << ";
      msg2 = " >> " + textboxes.get(1).Text;
      pressed = 1;
    }
  }
}

sorry, is that the same code you posted
Time of actions here?

and why make a new topic after
in the old one you answer 2 times with the ?same? text?


anyhow you confirmed that the arduino trigger works already
( and so the arduino category is misleading )

but the timeout for the text display NOT WORK?
inhowfar? it not stop display that text?
where in your code you try that?


so can you please delete your code here and
invest the 15min to make a code ONLY with the timer issue ( and a test text )

BUT NOT use any library / arduino communication / operation …
just a 10 line RUNable code so we can play with it and try to help
with the timer question only.

thanks, sorry for this but i didm’t know more of the coding. Arduino is working and Processing too. Anyway i try to copy my code to display only the image.
( the action could be: count for 2 minutes and read an image for 5 second then will be display black background ). Why it is not working ?

float count;
PImage fragment;
int rand; \ READ AN IMAGE RANDOM
float count2;

void setup() {
size(1200, 700);
count = 0;

rand = int (random(0, 3 ));
count2= 0;
}

void draw() {

count ++;

if (count > 200) {  \\ AFTER 2 SECOND DISPLAY A BLACK BACKGROUND
  fill(0);
  rect(0, 0, 1200, 700);

  count = 0;
}

count ++;

if (count2 > 300) {  \\ AFTER 3 SECOND DISPLAY A RANDOM IMAGE
 takerandomimage("image" + nf(rand, 3) + ".jpg");

  count = 0;
}

}

void takerandomimage(String fn) {
fragment = loadImage(fn);
image(fragment, 0, 0);
}

draw runs 60 times per second, so your count won’t work

In fact draw runs not reliable fast but has slower and faster moments

Look at millis () and make a timer

can you write the right sketch ? please because i don’t know the millis funciont ()

the last code you posted has nothing to do with the timer from your first code,
and again it uses some ( in respect of the question ) useless

loadimage

function what requires files we not have so we can not run that code.

also why suddenly you can not post code anymore?

</> code tag
type or paste code here

for other timer can also search here
https://discourse.processing.org/search?q=millis%20timer
but i am mainly interested in your timer code part
you have in your original code, and why it is not working?
how you code and test it first time?

i can copy all sketch

import codeanticode.syphon.*;

import processing.serial.*;

Serial myPort; // Create object from Serial class
int val; // Data received from the serial port

SyphonServer server;
float x = 0;
ArrayList textboxes = new ArrayList();

boolean send = false;
String msg = “”;
String msg2 = “”;

int pressed = 0;

Timer startTimer;

float count;
PImage fragment;
int rand;

float count2;

void setup() {
size(1200, 700, P3D);
printArray(Serial.list());
String portName = Serial.list()[2];
myPort = new Serial(this, portName, 115200);

server = new SyphonServer(this, “Processing Syphon”);
startTimer = new Timer(10);

InitLayout();

count = 0;

rand = int (random(0, 3 ));
}

void draw() {
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
}

if (val == 1) { // sensor triggered
background(0);
PFont f = createFont (“Georgia”, 40);
textFont(f);
textSize(20);

String s = " Try to sit in two chairs between a table ";
text(s, 415, 100);
String l = " Choose a shot of alcohol or juice, water or nothing too and stay in silence mode ";
text(l, 232, 600);

count ++;

if (count > 200) { 
  fill(0);
  rect(0, 0, 1200, 700);

  count = 0;
}

// start timer
startTimer.countDown();
if (startTimer.getTime() <= 0) {
  println("Do something");
}

} else {
background(200);

count ++;
if (count > 300) {
takerandomimage(“image” + nf(rand, 3) + “.jpg”);

  count = 0;
}


PFont f = createFont ("Georgia", 40);
PFont z = createFont ("Georgia", 30);
PFont d = createFont ("Georgia", 80);
if (pressed !=1) {

  String c = "Try to write in the Text boxes the words ";
  // String s = " sit in two chairs between a table. They will get a shot of alcohol or juice, water or nothing too and ";

  //textFont(f);
  // textSize(20);
  //  text(s, 100, 100);


  textFont(d);
  textSize(20);
  text(c, 100, 400);
  color(20);

  for (TEXTBOX t : textboxes) {
    t.DRAW();
  }
}

}
if (send) {
text(msg, (width/2 - textWidth(msg)), 260);
text(msg2, width/2, 260);
startTimer.countDown();
color(240);
fill(0);
text(startTimer.getTime(), width/2-40, 290);
}
server.sendScreen();
}

void InitLayout() {
TEXTBOX receiver = new TEXTBOX();
receiver.W = 500;
receiver.H = 50;
receiver.X = (width - receiver.W) / 13;
receiver.Y = 200;

textboxes.add(receiver);

TEXTBOX message = new TEXTBOX((width - receiver.W) / 13, 265, 500, 50);
textboxes.add(message);
}

void mousePressed() {
for (TEXTBOX t : textboxes) {
t.PRESSED(mouseX, mouseY);
}
}

void keyPressed() {
for (TEXTBOX t : textboxes) {
if (t.KEYPRESSED(key, keyCode)) {
send = true;
msg = textboxes.get(0).Text + " << ";
msg2 = " >> " + textboxes.get(1).Text;
pressed = 1;
}
}
}

void takerandomimage(String fn) {
fragment = loadImage(fn);
image(fragment, 0, 0);
}

no, i was referring to your

   // start timer
    startTimer.countDown();
    if (startTimer.getTime() <= 0) {
      println("Do something");
    }

tell us more about this please.

just a remark, not interfering


int timer; 
int i;

void setup() {
  size(555, 555);
  background(0);
  timer = millis();
}

void draw() {
  background(0);

  if (millis()-timer > 1000) {
    timer = millis();
    i++;
  }
  text(i, 33, 33);
}//
//