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;
    }
  }
}

What does it do now? What, specifically, are you trying to change so that it will do something different?

and can you please confirm that you
see

what starts your

or, what i suspect is that you never had a successful
detection of a arduino send value?

THANKS :slight_smile:

  1. I connected ardunio with Processing and a “Syphon” like visual bridge to project with a beamer using a laptop. it’s working

  2. When the sensor is triggered Processing display a black background with a string.

  3. I can’t write the right code, but i’d like to add this: if the sensor is triggered for 30 seconds, after 30 second not display the string in the background

THANKS :slight_smile:

  • I connected ardunio with Processing and a “Syphon” like visual bridge to project with a beamer using a laptop. it’s working
  • When the sensor is triggered Processing display a black background with a string.
  • I can’t write the right code, but i’d like to add this: if the sensor is triggered for 30 seconds, after 30 second not display the string in the background