Enable communication

This commit is contained in:
Dennis Schoepf 2020-09-25 15:09:36 +02:00
parent bcaeff80ed
commit 70f7b0d03e
4 changed files with 98 additions and 85 deletions

View file

@ -2,32 +2,25 @@
#include <SharpIR.h>
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);
}

View file

@ -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")) {
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
if (objectPlacedDown == true) {
backgroundOffset = backgroundOffset + velocity;
println(backgroundOffset);
}
// Draw fly-over objects
for (int i = 0; i < flyOverObjects.size(); i++) {
@ -77,9 +86,9 @@ void draw() {
shape(object);
}
if (cameIntoThreshhold == true) {
/* START - Create and animate placementIndicator */
// TODO: Trigger when first sensor is actuated
placementIndicator(width / 2+ 150, (height / 2) - backgroundOffset ,130, 8, placementIndicatorOffsetX);
placementIndicator(width / 2, (height / 2) + 220 - backgroundOffset ,110, 8, placementIndicatorOffsetX);
if (placementIndicatorAnimationCounter < 5) {
if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX < 30) {
@ -99,6 +108,7 @@ void draw() {
placementIndicatorOffsetX = 0;
}
/* 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 */

View file

@ -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")) {
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
if (objectPlacedDown == true) {
backgroundOffset = backgroundOffset + velocity;
println(backgroundOffset);
}
// Draw fly-over objects
for (int i = 0; i < flyOverObjects.size(); i++) {
@ -95,9 +104,9 @@ public void draw() {
shape(object);
}
if (cameIntoThreshhold == true) {
/* START - Create and animate placementIndicator */
// TODO: Trigger when first sensor is actuated
placementIndicator(width / 2 + 100, (height / 2) - backgroundOffset ,130, 8, placementIndicatorOffsetX);
placementIndicator(width / 2, (height / 2) + 220 - backgroundOffset ,110, 8, placementIndicatorOffsetX);
if (placementIndicatorAnimationCounter < 5) {
if (placementIndicatorAnimationDirection == "right" && placementIndicatorOffsetX < 30) {
@ -117,6 +126,7 @@ public void draw() {
placementIndicatorOffsetX = 0;
}
/* 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 */