We are about to switch to a new forum software. Until then we have removed the registration on this forum.
First, Sorry for my bad English,
hello, I've post about this several month ago, but as I continued my project, the more I need to figure out.
I'm doing an installation which is looped/interactive , when there's no hand detected by Leap Motion, my installation only display the looped code which is very simple delay code, (Arduino only) but if there's hand detect by Leap Motion, then convert to the code which I wrote for interactive (Processing+Arduino+leapmotion), but as the interactive part start, I want my original looped code still running,
for example , {A} is my original looped display, {B} is Leap motion interactive code,
{A}------(hand detected)----------------{hand removed}-----------------{A}
{B}------------{B}
my original looped code don't pause or stop, just covered by the Leapmotion code.
and here is my looped code (Arduino, nothing special, only delay) :
int ledPin = 1;
int ledPin2 = 2;
int ledPin3 = 3;
int ledPin4 = 4;
int ledPin5 = 5;
int ledPin6 = 6;
int ledPin7 = 7;
int ledPin8 = 8;
int ledPin9 = 9;
int ledPin10 = 10;
int ledPin11 = 11;
int ledPin12 = 12;
int ledPin13 = 13;
int ledPin14 = 14;
int laser = 15;
int laser2 = 16;
int laser3 = 17;
int laser4 = 18;
int laser5 = 19;
int laser6 = 20;
int laser7 = 21;
int laser8 = 22;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(ledPin8, OUTPUT);
pinMode(ledPin9, OUTPUT);
pinMode(ledPin10, OUTPUT);
pinMode(ledPin11, OUTPUT);
pinMode(ledPin12, OUTPUT);
pinMode(ledPin13, OUTPUT);
pinMode(ledPin14, OUTPUT);
pinMode(laser, OUTPUT);
pinMode(laser2, OUTPUT);
pinMode(laser3, OUTPUT);
pinMode(laser4, OUTPUT);
pinMode(laser5, OUTPUT);
pinMode(laser6, OUTPUT);
pinMode(laser7, OUTPUT);
pinMode(laser8, OUTPUT);
}
void loop() {
// laser part 01
delay(15000);
digitalWrite(laser, HIGH);
delay(1500);
digitalWrite(laser, LOW);
delay(6500);
digitalWrite(laser3, HIGH);
delay(1500);
digitalWrite(laser3, LOW);
delay(6500);
digitalWrite(laser5, HIGH);
delay(1500);
digitalWrite(laser5, LOW);
delay(6500);
digitalWrite(laser7, HIGH);
delay(1500);
digitalWrite(laser7, LOW);
delay(3000);
digitalWrite(laser2, HIGH);
delay(700);
digitalWrite(laser2, LOW);
delay(3000);
digitalWrite(laser4, HIGH);
delay(700);
digitalWrite(laser4, LOW);
delay(3000);
digitalWrite(laser6, HIGH);
delay(700);
digitalWrite(laser6, LOW);
delay(3000);
digitalWrite(laser8, HIGH);
delay(700);
digitalWrite(laser8, LOW);
delay(34000);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, HIGH);
digitalWrite(ledPin7, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
delay(500);
digitalWrite(laser, HIGH);
delay(500);
digitalWrite(laser, LOW);
delay(500);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin13, HIGH);
digitalWrite(ledPin14, HIGH);
delay(500);
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);
digitalWrite(ledPin11, LOW);
digitalWrite(ledPin12, LOW);
digitalWrite(ledPin13, LOW);
digitalWrite(ledPin14, LOW);
delay(1500);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, HIGH);
digitalWrite(ledPin7, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
delay(500);
digitalWrite(laser2, HIGH);
delay(500);
digitalWrite(laser2, LOW);
delay(500);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin13, HIGH);
digitalWrite(ledPin14, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
delay(1500);
digitalWrite(laser3, HIGH);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, HIGH);
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin13, HIGH);
digitalWrite(ledPin14, HIGH);
delay(500);
digitalWrite(laser3, LOW);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
digitalWrite(ledPin7, LOW);
digitalWrite(ledPin8, LOW);
digitalWrite(ledPin9, LOW);
digitalWrite(ledPin10, LOW);
digitalWrite(ledPin11, LOW);
digitalWrite(ledPin12, LOW);
digitalWrite(ledPin13, LOW);
digitalWrite(ledPin14, LOW);
delay(500);
digitalWrite(laser4, HIGH);
delay(500);
digitalWrite(laser, LOW);
delay(500);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, HIGH);
digitalWrite(ledPin7, HIGH);
digitalWrite(ledPin8, HIGH);
digitalWrite(ledPin9, HIGH);
digitalWrite(ledPin10, HIGH);
digitalWrite(ledPin11, HIGH);
digitalWrite(ledPin12, HIGH);
digitalWrite(ledPin13, HIGH);
digitalWrite(ledPin14, HIGH);
delay(500);
}
and this is my interactive code (Arduino) :
int val; // Data received from the serial port
int ledPin = 13; // Set the pin to digital I/O 13
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int ledPin5 = 9;
int ledPin6 = 8;
void setup() {
pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
if (Serial.available())
{ // If data is available to read,
val = Serial.read(); // read it and store it in val
}
if (val == 1)
{ // If 1 was received
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, HIGH);
digitalWrite(ledPin4, HIGH);
digitalWrite(ledPin5, HIGH);
digitalWrite(ledPin6, HIGH);// turn the LED on
} else if (val == 0) {
digitalWrite(ledPin, LOW); // otherwise turn it off
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
digitalWrite(ledPin4, LOW);
digitalWrite(ledPin5, LOW);
digitalWrite(ledPin6, LOW);
}
delay(10); // Wait 10 milliseconds for next reading
}
this is my interactive code (Processing):
import de.voidplus.leapmotion.*;
import processing.serial.*;
Serial myPort;
LeapMotion leap ;
void setup () {
size(800, 500);
background(255);
leap = new LeapMotion(this);
String portName = Serial.list()[1]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 9600);
}
boolean rightHand,leftHand;
float posy ;
float posx ;
void draw() {
int number=0;
for (Hand hand : leap.getHands() ) {
rightHand = hand.isRight();
posy = hand.getPosition().y;
number=hand.countFingers();
hand.draw();
//println("Hand palm position: "+hand.getPalmPosition());
}
//println(number);
println(posy);
if(rightHand){
if ((number!= 0)&&(posy < 450 && posy > 350))
{
timer(128); //send a 1
println("1");
} else if ((number!= 0)&&(posy < 350 && posy > 250))
{
timer(32);
println("2");
} else if ((number!= 0)&&(posy < 250 && posy > 150))
{
timer(8);
println("3");
} else if ((number!= 0)&&(posy < 150 && posy > -120))
{
timer(4);
println("4");
} else
{ //otherwise
myPort.write(0); //send a 0
}
}else if(leftHand){
}
delay(30);
}
void timer(int step) {
if (frameCount % step ==0) {
myPort.write(1);
} else if (frameCount % step == step/2) {
myPort.write(0);
}
}
I want to put these code together as one, please help me, thank you for your reading and apologize for my bad english again.
Answers
Something is not clear:
So you have both codes merged already? But the n you say:
Which code are you referring to?
So, processing handles leapMotion and Processing drives the arduino. If the arduino receives data from leapMotion (via Processing) the arduino should do both the original code and the interactive(leapMotion) code?
Kf
yes, because I've set times for my looped code, so I want after my leapmotion code ends, my original code continues where it should be.
for example, the original code is led light up for five times in 10 sec, so when my leapmotion code triggered and last for 3sec, I want the last led ends at 10sec instead of 13 sec.
hope its clear and sorry for making you misunderstanding :(