Control this code with arduino
in
Contributed Library Questions
•
5 months ago
Hi guys,
I'd like to get this app working with my arduino:
- import toxi.geom.*;
- import toxi.geom.mesh2d.*;
- // empty voronoi mesh container
- Voronoi voronoi = new Voronoi();
- // switches
- boolean doShowPoints = false;
- boolean doShowDelaunay;
- void setup() {
- size(600, 600);
- smooth();
- textFont(createFont("SansSerif", 10));
- }
- 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);
- }
- }
- if(!online)saveFrame("frame.png");
- }
- 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;
- }
- }
Here is the arduino code:
- int swiPin [] = {2, 3};
- boolean currentButtonVal[2];
- //Grouping of combinations
- int groupA;
- void setup(){
- for(int x = 0; x<2; x++){
- pinMode(swiPin[x], INPUT);
- digitalWrite(swiPin[x], HIGH);
- currentButtonVal[x] = HIGH;
- }
- Serial.begin(9600);
- }
- void check_fingering(){
- //Check keys pressed
- groupA = 1*(!debounce(0)) + 2*(!debounce(1)) + 4*(!debounce(2)) + 8*(!debounce(3));
- }
- boolean debounce(int thisButton) {
- boolean current = digitalRead(swiPin[thisButton]);
- if (currentButtonVal[thisButton] != current) {
- delay(5);
- current = digitalRead(swiPin[thisButton]);
- }
- currentButtonVal[thisButton] = current; // store new state for your pin
- return current;
- }
- void loop(){
- check_fingering();
- if (groupA == 1){
- Serial.println("x");
- Serial.flush();
- }
- else if (groupA == 2){
- Serial.println("r");
- Serial.flush();
- }
- }
Thank you for your help.
1