diff --git a/magic-veneer-arduino/src/main.cpp b/magic-veneer-arduino/src/main.cpp index a6381ce..8dac37c 100644 --- a/magic-veneer-arduino/src/main.cpp +++ b/magic-veneer-arduino/src/main.cpp @@ -2,32 +2,25 @@ #include SharpIR sensorProx(SharpIR::GP2Y0A02YK0F, A0); -SharpIR sensorDown(SharpIR::GP2Y0A02YK0F, A1); +SharpIR sensorDown(SharpIR::GP2Y0A02YK0F, A7); void setup() { Serial.begin(9600); pinMode(A0, INPUT); - pinMode(A1, INPUT); + pinMode(A7, INPUT); } void loop() { int distanceProx = sensorProx.getDistance(); - int distanceDown = sensorDown.getDistance(); - Serial.print("Proximity"); - Serial.println(distanceProx); - Serial.print("Down"); - Serial.println(distanceDown); - delay(100); + // int distanceDown = sensorDown.getDistance(); + delay(250); - if (distanceProx < 40) + if (distanceProx < 30) { - Serial.println("Through first barrier"); + Serial.println("indicatePlacement"); + delay(2000); + Serial.println("startAnimation"); } - if (distanceDown < 35) - { - Serial.println("Through second barrier"); - } - delay(100); } \ No newline at end of file diff --git a/magic_veneer_processing/magic_veneer_processing.pde b/magic_veneer_processing/magic_veneer_processing.pde index 4bd4b73..8e2ee07 100644 --- a/magic_veneer_processing/magic_veneer_processing.pde +++ b/magic_veneer_processing/magic_veneer_processing.pde @@ -3,6 +3,7 @@ import processing.serial.*; Serial arduinoPort; String receivedMessage; boolean cameIntoThreshhold = false; +boolean objectPlacedDown = false; PShape branch; PShape leftWing; @@ -27,7 +28,6 @@ void setup() { fullScreen(); background(0); - /* Load external files */ branch = loadShape("branch.svg"); leftWing = loadShape("leftwing.svg"); @@ -44,32 +44,41 @@ void setup() { flyOverObjects.add(object); } - - /* Set up communication with arduino + /* Set up communication with arduino */ String portName = Serial.list()[Serial.list().length - 1]; //change index to match your port - arduinoPort = new Serial(this, portName, 9600); */ + arduinoPort = new Serial(this, portName, 9600); } void draw() { - /* if ( arduinoPort.available() > 0) { + if ( arduinoPort.available() > 0) { String rec = arduinoPort.readStringUntil('\n'); if (rec != null) { receivedMessage = rec; } // Check for specific events and act upon them - if (receivedMessage != null && receivedMessage.contains("isWithinThreshhold")) { - cameIntoThreshhold = true; + if (receivedMessage != null) { + if (receivedMessage.contains("indicatePlacement")) { + cameIntoThreshhold = true; + } else { + cameIntoThreshhold = false; + } + + if (receivedMessage.contains("startAnimation")) { + objectPlacedDown = true; + } else { + objectPlacedDown = false; + } } - }*/ + } // Set up fill and let background move background(0); translate(0, backgroundOffset - 100); - // TODO: Only start to move background as soon as second sensor is triggered - backgroundOffset = backgroundOffset + velocity; - println(backgroundOffset); + if (objectPlacedDown == true) { + backgroundOffset = backgroundOffset + velocity; + } // Draw fly-over objects for (int i = 0; i < flyOverObjects.size(); i++) { @@ -77,28 +86,29 @@ void draw() { shape(object); } - /* START - Create and animate placementIndicator */ - // TODO: Trigger when first sensor is actuated - placementIndicator(width / 2+ 150, (height / 2) - backgroundOffset ,130, 8, placementIndicatorOffsetX); + if (cameIntoThreshhold == true) { + /* START - Create and animate placementIndicator */ + placementIndicator(width / 2, (height / 2) + 220 - backgroundOffset ,110, 8, placementIndicatorOffsetX); - if (placementIndicatorAnimationCounter < 5) { - if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX < 30) { - placementIndicatorOffsetX += 2; - } else if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX <= 30) { - placementIndicatorAnimationDirection = "left"; - placementIndicatorOffsetX -= 2; - placementIndicatorAnimationCounter++; - } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX >= -30) { - placementIndicatorOffsetX -= 2; - } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX <= -30) { - placementIndicatorAnimationDirection = "right"; - placementIndicatorOffsetX += 2; - placementIndicatorAnimationCounter++; + if (placementIndicatorAnimationCounter < 5) { + if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX < 30) { + placementIndicatorOffsetX += 2; + } else if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX <= 30) { + placementIndicatorAnimationDirection = "left"; + placementIndicatorOffsetX -= 2; + placementIndicatorAnimationCounter++; + } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX >= -30) { + placementIndicatorOffsetX -= 2; + } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX <= -30) { + placementIndicatorAnimationDirection = "right"; + placementIndicatorOffsetX += 2; + placementIndicatorAnimationCounter++; + } + } else { + placementIndicatorOffsetX = 0; } - } else { - placementIndicatorOffsetX = 0; + /* END - Create and animate placementIndicator */ } - /* END - Create and animate placementIndicator */ /* START - Scene 1 Bugs going by */ bug(100, -100, 1); @@ -110,7 +120,7 @@ void draw() { if (backgroundOffset < 2450) { /* START - Scene 2 Crawling on branch */ - shape(branch, 0, -3200, width, width); + shape(branch, 0, -2980, width, width); /* END - Scene 2 Crawling on branch */ } else if (backgroundOffset > 2450 && backgroundOffset < 4400) { if (cocoonAnimationFinished == false) { @@ -128,10 +138,10 @@ void draw() { fill(255); noStroke(); - arc(width / 2 + 150, -1800 - (backgroundOffset - 2450), 500, 1100, radians(260 - cocoonOpenDegrees), radians(280 + cocoonOpenDegrees), PIE); + arc(width / 2, -1580 - (backgroundOffset - 2450), 500, 1100, radians(260 - cocoonOpenDegrees), radians(280 + cocoonOpenDegrees), PIE); print("Tree position: "); - shape(branch, 0, -3200 - (backgroundOffset - 2450), width, width); + shape(branch, 0, -2980 - (backgroundOffset - 2450), width, width); } // 3. Let tree move again @@ -158,8 +168,8 @@ void draw() { wingWidth += 4; } - shape(leftWing, width / 2 - wingWidth + 85, (height / 2 - wingWidth * 0.8) - backgroundOffset, wingWidth, wingWidth * 1.5); - shape(rightWing, width / 2 + 215, (height / 2 - wingWidth * 0.8) - backgroundOffset, wingWidth, wingWidth * 1.5); + shape(leftWing, width / 2 - wingWidth - 65, (height / 2 - wingWidth * 0.8 + 220) - backgroundOffset, wingWidth, wingWidth * 1.5); + shape(rightWing, width / 2 + 65, (height / 2 - wingWidth * 0.8 + 220) - backgroundOffset, wingWidth, wingWidth * 1.5); /* END - Scene 4 Butterfly */ diff --git a/magic_veneer_processing/out/magic_veneer_processing.class b/magic_veneer_processing/out/magic_veneer_processing.class index cd292e3..3954771 100644 Binary files a/magic_veneer_processing/out/magic_veneer_processing.class and b/magic_veneer_processing/out/magic_veneer_processing.class differ diff --git a/magic_veneer_processing/out/source/magic_veneer_processing.java b/magic_veneer_processing/out/source/magic_veneer_processing.java index b47a3ec..60282f3 100644 --- a/magic_veneer_processing/out/source/magic_veneer_processing.java +++ b/magic_veneer_processing/out/source/magic_veneer_processing.java @@ -21,6 +21,7 @@ public class magic_veneer_processing extends PApplet { Serial arduinoPort; String receivedMessage; boolean cameIntoThreshhold = false; +boolean objectPlacedDown = false; PShape branch; PShape leftWing; @@ -45,7 +46,6 @@ public void setup() { background(0); - /* Load external files */ branch = loadShape("branch.svg"); leftWing = loadShape("leftwing.svg"); @@ -62,32 +62,41 @@ public void setup() { flyOverObjects.add(object); } - - /* Set up communication with arduino + /* Set up communication with arduino */ String portName = Serial.list()[Serial.list().length - 1]; //change index to match your port - arduinoPort = new Serial(this, portName, 9600); */ + arduinoPort = new Serial(this, portName, 9600); } public void draw() { - /* if ( arduinoPort.available() > 0) { + if ( arduinoPort.available() > 0) { String rec = arduinoPort.readStringUntil('\n'); if (rec != null) { receivedMessage = rec; } // Check for specific events and act upon them - if (receivedMessage != null && receivedMessage.contains("isWithinThreshhold")) { - cameIntoThreshhold = true; + if (receivedMessage != null) { + if (receivedMessage.contains("indicatePlacement")) { + cameIntoThreshhold = true; + } else { + cameIntoThreshhold = false; + } + + if (receivedMessage.contains("startAnimation")) { + objectPlacedDown = true; + } else { + objectPlacedDown = false; + } } - }*/ + } // Set up fill and let background move background(0); translate(0, backgroundOffset - 100); - // TODO: Only start to move background as soon as second sensor is triggered - backgroundOffset = backgroundOffset + velocity; - println(backgroundOffset); + if (objectPlacedDown == true) { + backgroundOffset = backgroundOffset + velocity; + } // Draw fly-over objects for (int i = 0; i < flyOverObjects.size(); i++) { @@ -95,28 +104,29 @@ public void draw() { shape(object); } - /* START - Create and animate placementIndicator */ - // TODO: Trigger when first sensor is actuated - placementIndicator(width / 2 + 100, (height / 2) - backgroundOffset ,130, 8, placementIndicatorOffsetX); + if (cameIntoThreshhold == true) { + /* START - Create and animate placementIndicator */ + placementIndicator(width / 2, (height / 2) + 220 - backgroundOffset ,110, 8, placementIndicatorOffsetX); - if (placementIndicatorAnimationCounter < 5) { - if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX < 30) { - placementIndicatorOffsetX += 2; - } else if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX <= 30) { - placementIndicatorAnimationDirection = "left"; - placementIndicatorOffsetX -= 2; - placementIndicatorAnimationCounter++; - } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX >= -30) { - placementIndicatorOffsetX -= 2; - } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX <= -30) { - placementIndicatorAnimationDirection = "right"; - placementIndicatorOffsetX += 2; - placementIndicatorAnimationCounter++; + if (placementIndicatorAnimationCounter < 5) { + if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX < 30) { + placementIndicatorOffsetX += 2; + } else if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX <= 30) { + placementIndicatorAnimationDirection = "left"; + placementIndicatorOffsetX -= 2; + placementIndicatorAnimationCounter++; + } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX >= -30) { + placementIndicatorOffsetX -= 2; + } else if (placementIndicatorAnimationDirection == "left" && placementIndicatorOffsetX <= -30) { + placementIndicatorAnimationDirection = "right"; + placementIndicatorOffsetX += 2; + placementIndicatorAnimationCounter++; + } + } else { + placementIndicatorOffsetX = 0; } - } else { - placementIndicatorOffsetX = 0; + /* END - Create and animate placementIndicator */ } - /* END - Create and animate placementIndicator */ /* START - Scene 1 Bugs going by */ bug(100, -100, 1); @@ -128,7 +138,7 @@ public void draw() { if (backgroundOffset < 2450) { /* START - Scene 2 Crawling on branch */ - shape(branch, 0, -3200, width, width); + shape(branch, 0, -2980, width, width); /* END - Scene 2 Crawling on branch */ } else if (backgroundOffset > 2450 && backgroundOffset < 4400) { if (cocoonAnimationFinished == false) { @@ -146,10 +156,10 @@ public void draw() { fill(255); noStroke(); - arc(width / 2 + 100, -1800 - (backgroundOffset - 2450), 500, 1100, radians(260 - cocoonOpenDegrees), radians(280 + cocoonOpenDegrees), PIE); + arc(width / 2, -1580 - (backgroundOffset - 2450), 500, 1100, radians(260 - cocoonOpenDegrees), radians(280 + cocoonOpenDegrees), PIE); print("Tree position: "); - shape(branch, 0, -3200 - (backgroundOffset - 2450), width, width); + shape(branch, 0, -2980 - (backgroundOffset - 2450), width, width); } // 3. Let tree move again @@ -176,8 +186,8 @@ public void draw() { wingWidth += 4; } - shape(leftWing, width / 2 - wingWidth + 35, (height / 2 - wingWidth * 0.8f) - backgroundOffset, wingWidth, wingWidth * 1.5f); - shape(rightWing, width / 2 + 165, (height / 2 - wingWidth * 0.8f) - backgroundOffset, wingWidth, wingWidth * 1.5f); + shape(leftWing, width / 2 - wingWidth - 65, (height / 2 - wingWidth * 0.8f + 220) - backgroundOffset, wingWidth, wingWidth * 1.5f); + shape(rightWing, width / 2 + 65, (height / 2 - wingWidth * 0.8f + 220) - backgroundOffset, wingWidth, wingWidth * 1.5f); /* END - Scene 4 Butterfly */