Problem turning this processing sketch arduino compatible

Hi guys,

This is my first post here, hope it’s not too noobish.
I am trying to turn this processing sketch arduino compatible, but I can’t find the right way. I’d like to control the R and X letters with the 2 buttons connected to my breadboard.
This is how I imagine the solution: if I press down the button connected to pin one, it switches to HIGH and creates the same effect as I was pressing down the key, R. - the same with my other button.

here is the code:

import toxi.geom.*;
import toxi.geom.mesh2d.*;
 
// empty voronoi mesh container
Voronoi voronoi = new Voronoi();
 
// switches
boolean doShowPoints=false;
boolean doShowDelaunay;
boolean doShowHelp=false;
 
void setup() {
  size(600, 600);
  smooth();
  
}
 
void draw() {
  background(255);
  stroke(0);
  noFill();
 
  // draw delaunay triangulation
  if (doShowDelaunay) {
    stroke(0, 0, 255, 50);
    beginShape(TRIANGLES);
    for (Triangle2D t : voronoi.getTriangles()) {
      triangle(t.a.x, t.a.y, t.b.x, t.b.y, t.c.x, t.c.y);
    }
    endShape();
  }else {
    // draw all voronoi polygons, clip them if needed...
    for (Polygon2D poly : voronoi.getRegions()) {
      beginShape();
      for(Vec2D vector : poly.vertices){
        vertex(vector.x,vector.y);
      }
      endShape(CLOSE);
    }
  }
  // draw original points added to voronoi
  if (doShowPoints) {
    fill(255, 0, 255);
    noStroke();
    for (Vec2D c : voronoi.getSites()) {
      ellipse(c.x, c.y, 5, 5);
    }
  }
}
 
void keyPressed() {
  
  switch(key) {
  case 'x':
    voronoi = new Voronoi();
    break;
  case 'r':
    for (int i = 0; i < 10; i++) {
      voronoi.addPoint(new Vec2D(random(width), random(height)));
    }
    break;
  }
}

thanks for you help :slight_smile:

The processing sketch has nothing that would be Arduino specific, so there is nothing to convert.

You want code on the Arduino to detect button presses (of which tons of examples exist) and transmit it over serial to processing (of which examples exists) so that processing can know when a button is pressed.

[quote author=James C4S link=topic=163749.msg1223006#msg1223006 date=1367349449] The processing sketch has nothing that would be Arduino specific, so there is nothing to convert.

You want code on the Arduino to detect button presses (of which tons of examples exist) and transmit it over serial to processing (of which examples exists) so that processing can know when a button is pressed. [/quote]

Alright, I understand. Could you send me an example that detects button presses? I have the Arduino Uno. Thanks for your help.

Have you looked at any of the examples that come with the Arduino IDE?

AWOL: Have you looked at any of the examples that come with the Arduino IDE?

Yes I did, in the USB folder. I either get an error message: 'Keyboard' was not declared in this scope, or "it's supported by Arduino Leonardo only"

any other solution?

The Keyboard examples are for if you are using the Arduino Leonardo (not Uno) as a USB Keyboard.

I said you want example code that detect buttons presses and communicates with Serial.

Under Digital is a “Button” example. Under “Communication” are a lot of Serial type examples.

Why the USB folder? The buttons aren't USB devices, are they?

DigitalReadSerial would seem to me a better place.

AWOL: Why the USB folder? The buttons aren't USB devices, are they?

DigitalReadSerial would seem to me a better place.

probaby because this is my second day learning arduino/processing and I've had a hard time finding it. anyways, thank you all for your responses and I hope next time I will have more accurate questions.