We are about to switch to a new forum software. Until then we have removed the registration on this forum.
**Hello, **
I am working on my last year project for my highschool, and I am creating an invisible entry system that I control with my fingers.
(http://forum.processing.org/two/uploads/imageupload/481/QU4DV0AOJDBA.png "lmulz")
The black squares represent where your fingers have to go to open the gate, and the red ellipse represents my finger.
I am using a Leap Motion, Processing, and Arduino, but here's my problem :
I want someone to be able to create it's own digital code by creating a zone represented by a square, but I don't know how to do it. For the moment I use a noLoop(); after the creation of the square, but it stops my program ofc.
So, I am able to create a square that doesn't move according to my finger anymore, bu that completely my program.. ** Here is my code : **
import processing.serial.*;
import de.voidplus.leapmotion.*;
import development.*;
Serial portUSB;
int inByte;
int x,y;
int p,q;
int a;
LeapMotion leap; // creation de l'objet leap
ArrayList<PVector> points; //tableau pour contennir le tracé
ArrayList<PVector> points2;
PVector fp; // vector de la position des doigts
void setup()
{
size(800, 800, P3D);
background(125,125,125);
println(Serial.list());
portUSB = new Serial(this, Serial.list()[1], 9600);
leap = new LeapMotion(this);
points = new ArrayList<PVector>(); // Create an empty ArrayList
points2 = new ArrayList<PVector>();
smooth(8);
noStroke();
a = 1;
x = 150;
y = 150;
p = 450;
q = 450;
}
void draw()
{
rect(x,y,150,150);
rect(p,q,150,150);
fill(0);
int fps = leap.getFrameRate();
frameRate(fps);
// Mains
for (Hand hand : leap.getHands())
{
// Doigts
for (Finger finger : hand.getFingers())
{
fp = finger.getPosition(); // retourne la position des doigts sous forme de vecteur
nettoyer();
mdr();
}
}
}
void nettoyer()
{
background(125,125,125);
}
void mdr()
{
rect(x,y,150,150);
rect(p,q,150,150);
fill(0);
if (fp.z > 40 )
{
fill(255,0,0);
ellipse(fp.x, fp.y, constrain(fp.z, 10, 20), constrain(fp.z, 10, 20));
}
if (fp.x > x && fp.x < x+150 && fp.y > y && fp.y < y+150 )
{
if(a == 1)
{
points.add(new PVector(fp.x, fp.y));
println("LES SAUCISSES");
a++;
}
}
if (fp.x > p && fp.x < p+150 && fp.y > q && fp.y < q+150 )
{
if(a == 2)
{
points.add(new PVector(fp.x, fp.y));
portUSB.write(67);
println(67);
a++;
}
}
if(fp.z > 65)
{
rect(fp.x-75,fp.y-75,150,150);
fill(0,255,0);
points2.add(new PVector(fp.x, fp.y));
}
for (int i = points.size()-1; i >= 0; i--)
{
PVector p = points.get(i);
fill(255, 0, 0);
ellipse(p.x, p.y, 20, 20);
}
for (int u = points2.size()-1; u >= 0; u--)
{
PVector p = points2.get(u);
fill(0, 255, 0);
rect(fp.x-75,fp.y-75,150,150);
** noLoop();**
}
}
void keyPressed()
{
if(key == '1')
{
println("RESET");
portUSB.write(68);
a = 1;
points = new ArrayList<PVector>();
points2 = new ArrayList<PVector>();
nettoyer();
}
}
Thanks for your help, and sorry for my english. Ask me if you didn't understand something.
Answers
To format the source code highlight it so the code is selected and press Ctrl + k or click on the C button.
I have deleted your second post which was the same code as the first post.
Ok, thanks !
as far as I understand it, your program has two situations:
create it's own digital code by creating a zone represented by a square
use the invisible entry system that I control with my fingers.
At the moment you try to have noLoop after situation 1.
Instead think of states of the program.
state / situation 1 being: create it's own digital code
state / situation 2 being: use the invisible entry system
so you need a var "state" which can be 1 or 2
in draw() have a switch that goes
the rects e.g.
are only (not) drawn in state 2
Later
in case he later unlocked the door or failed to do so you can expand the states to
state you won
state you failed
Greetings, Chrisir
Thanks a lot! I will try to use this solution !
I tried your solution and it seems to match. The only problem is that I don't know how to switch from case1 to case2. And when I try to put the case 2 in a if() I get an error...
Here is my code now :
I don't get what mdr stands for
also I don't understand why you have switch in mdr and not in draw()
I expected in draw():
Greetings, Chrisir
Nevermind, I understood ! Ty !
Here's what I get now :
??
does it work?
switch state still in mdr, not in draw
what does mdr do?
you can end state 1 and go to state 2 when 9 is hit or when return / enter is hit e.g.
Well, I am sorry but I've just realized that I worked two differents versions, so some elements are missing in 2 last versions of my code.
I am working on it.
Well, yes it works. When I press 9, my state 2 is active. That's the only way I found for the moment, but this is the idea.
Sorry forgot to answer :
mdr stands for pretty much everything in fact..
I don't speak french so I can't understand some of your code
I'm sorry
In situation 1 : how many rects does he have to submit until he's done?
just count them and when he's finished say state = 2;
the big picture:
a more logical approach would be:
normally we all land in state 2
when he points in a certain way (three corners e.g.), he tells the system he is a admin
system asks for password
when password is right, state 1, he can change the lock, and save it
password and lock position is saved encrypted on hard-drive
because
because at the moment it's only a game without much purpose
with a use like above there would be a more substantial way to tackle the user scenario I think
For the moment, the gate is opened when you first go in the top-left square and then in the second, so there's no specific number.
The thing is that I am trying to use the square I create in the second caser, transfering it in the first case etc...
The problem I am facing is that I don't really know how to transfer the square from the state 2 to the state 1.
I can't run your code because I don't have serial etc.
but in theory, you paint two rects as a hidden lock in situation 2
is that right?
so in situation 1 when he defines the locks you need to
store his input in inputPosX1, inputPosY1 etc.
and when he hits 9 (goes to state 2) you say once
etc.
so you can use x and y and p and q in state 2
this is the idea....
NB
x,y and p,q here are upper left corner and lower right corner of the lock
there is only one lock.
state 0: Admin starts by defining it (user must look away) and then state 1: user must unlock
when he did state = 2 - he won
the states are used in draw() and in mouseClicked() also - very elegant
I don't get what you're trying to do in your second messsage, with the mouse game.
For the moment I am using keyboard, but the goal is to control everything with my fingers only, but I will work on this later.
it is a simulation to show how I see the connection of state 0 and state 1
you wrote
I wanted to give you an example on how to do that
you wrote
in the state 0 an admin is defining a rect and in the state 1 an user is searching the lock and trying to open it
the mouse is the replacement for what you do with the fingers
Oh okay! I'll read it again then. Thanks.
or rather load it and play with it in processing
I tried but the problem is that I can't write something like float w; w = fp.x (finger position axis x) so basically I don't know how to use this..
When I try to do w = fp.x it says that the com port 1 is busy..
so I can't say to my program that w is fp.x in case 2 and fp.x just itself in the first case, so the program confuses both fp.x and fails miserably.
I dunno
Maka a new post maybe?
Maybe I will.
Sorry, I didn't answer because I was in holidays, I didn't work much...
Thanks for all your help though. :)
;-)