Dear all,
I am trying use the Leap Motion sensor data to turn LED pins on and off using Arduino. Right now I am using a processing code that controls LED pins according to the hand position (x). I am trying to figure out how to make the LED pins turn on according to how many fingers are being detected. Can you please help me?
PROCESSING code I am using:
// An array of LEDs lit up by LEAP motion on an ARDUINO
// LEAP libraries
import de.voidplus.leapmotion.*;
LeapMotion leap;
// Serial Port Output
import processing.serial.*; // Serial libraries, send OUTPUT through USB
Serial myPort;
int ledPin;
int checkPin;
void setup() {
size(800, 500, P3D);
background(255);
noStroke();
fill(50);
// New port object
myPort = new Serial(this, Serial.list()[3], 9600);
// New leap object
leap = new LeapMotion(this);
}
void draw() {
background(255);
// Leap magic
int fps = leap.getFrameRate();
// Clean LEAP Hand position
for (Hand hand : leap.getHands()) {
hand.draw();
PVector hand_position = hand.getPosition();
// println(“Hand on X: ” + hand.getPosition().x );
// Determine ledPin according to mapped hand x position
checkPin = (int) map(hand.getPosition().x, 0, 700, 8, 14);
if (ledPin != checkPin) {
assignPin();
}
// Send ledPin number through port
}
}
void assignPin() {
ledPin = checkPin;
myPort.write(ledPin);
println("Serial Output: " + ledPin);
}
void leapOnInit() {
// println(“Leap Motion Init”);
}
void leapOnConnect() {
// println(“Leap Motion Connect”);
}
void leapOnFrame() {
// println(“Leap Motion Frame”);
}
void leapOnDisconnect() {
// println(“Leap Motion Disconnect”);
}
void leapOnExit() {
// println(“Leap Motion Exit”);
}
ARDUINO code:
// Arduino sketch turn LED on via serial input from Processing
// Define main variables
int ledPin = 0;
int currentRead;
// Slowing down the process
//unsigned long millisCounter = 0;
//int interval = 10;
// activate the pins I want to use on my board
int myPins[5] = {
9, 10, 11, 12, 13};
void setup() {
// Activate all Digital pins on my board
for (int i = 0; i < 5; i++) {
pinMode(myPins[i], OUTPUT);
}
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
currentRead = Serial.read();
if(currentRead != ledPin) {
digitalWrite(ledPin, LOW);
ledPin = currentRead;
digitalWrite(ledPin, HIGH);
}
}
}
I tried using the hand.countFingers function but it does not work, I would appreciate if someone could help me out with this