# Time of actions

**URL:** https://discourse.processing.org/t/time-of-actions/11629
**Category:** Electronics (Arduino, etc.)
**Created:** [May 27, 2019, 11:18am UTC](https://discourse.processing.org/t/time-of-actions/11629 "2019-05-27T11:18:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![aleandrosinatra](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@aleandrosinatra](https://discourse.processing.org/u/aleandrosinatra)
#### Post date: [May 27, 2019, 11:18am UTC](https://discourse.processing.org/t/time-of-actions/11629/1 "2019-05-27T11:18:51Z")

</div>

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.

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

```

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 27, 2019, 8:11pm UTC](https://discourse.processing.org/t/time-of-actions/11629/2 "2019-05-27T20:11:00Z")

</div>

> [@aleandrosinatra](#):
>
> I don’t understand to set a counter to make some operations.

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

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [May 28, 2019, 3:06am UTC](https://discourse.processing.org/t/time-of-actions/11629/3 "2019-05-28T03:06:29Z")

</div>

and can you please confirm that you  
see

> [@aleandrosinatra](#):
>
> if (val == 1) { // sensor triggered

what starts your

> [@aleandrosinatra](#):
>
> // start timer startTimer.countDown();

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

---

<div class="post-metadata">

### Author: ![aleandrosinatra](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@aleandrosinatra](https://discourse.processing.org/u/aleandrosinatra)
#### Post date: [May 28, 2019, 8:29am UTC](https://discourse.processing.org/t/time-of-actions/11629/4 "2019-05-28T08:29:28Z")

</div>

THANKS 🙂

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

---

<div class="post-metadata">

### Author: ![aleandrosinatra](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@aleandrosinatra](https://discourse.processing.org/u/aleandrosinatra)
#### Post date: [May 28, 2019, 8:30am UTC](https://discourse.processing.org/t/time-of-actions/11629/5 "2019-05-28T08:30:33Z")

</div>

THANKS 🙂

- 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
