Pada siang hari ini saya akan menjelaskan project ketiga saya menggunakan Leap Motion, kali ini alat yang dibuat adalah alat untuk kendali angle servo, jadi servo akan bergerak sesuai arah / posisi tangan berada, untuk aplikasinya sangat banyak sekali seperti halnya kendali robot lengan menggunakan tangan, kendali buka-tutup pintu dengan gesture tangan, dan lain sebagainya, komponen yang dibutuhkan tidaklah banyak yaitu Arduino Uno, Servo, dan Leap Motion. Untuk lebih jelasnya berikut adalah skema dan programnya.
a. Arduino Uno
b. Leap Motion
c. Motor Servo
d. Program Arduino IDE
#include <LiquidCrystal.h>
#include <Servo.h>
int currentRead;
Servo myservo;
LiquidCrystal lcd(8, 9, 10, 11, 12, 7);
void setup() {
myservo.attach(6);
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
}
void loop() {
if (Serial.available()) {
currentRead = Serial.read();
if (currentRead < 50)
{
currentRead = 50;
}
if (currentRead > 200)
{
currentRead = 200;
}
lcd.setCursor(0, 0);
lcd.print("Angle X = ");
lcd.print(currentRead);
myservo.write(currentRead);
delay(200);
lcd.clear();
}
#include <Servo.h>
int currentRead;
Servo myservo;
LiquidCrystal lcd(8, 9, 10, 11, 12, 7);
void setup() {
myservo.attach(6);
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.noCursor();
}
void loop() {
if (Serial.available()) {
currentRead = Serial.read();
if (currentRead < 50)
{
currentRead = 50;
}
if (currentRead > 200)
{
currentRead = 200;
}
lcd.setCursor(0, 0);
lcd.print("Angle X = ");
lcd.print(currentRead);
myservo.write(currentRead);
delay(200);
lcd.clear();
}
}
e. Program Processing IDE
e. Program Processing IDE
// 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;
int ok;
void setup() {
size(800, 500, P3D);
background(255);
noStroke();
fill(50);
// New port object
myPort = new Serial(this, Serial.list()[0], 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 );
ok = (int) (hand.getPosition().x);
myPort.write(ok);
println("Hand on Y: " + hand.getPosition().y );
// Determine ledPin according to mapped hand x position
delay(200);
}
}
void delay(int delay)
{
int time = millis();
while(millis()-time<=delay);
}
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”);
}
// 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;
int ok;
void setup() {
size(800, 500, P3D);
background(255);
noStroke();
fill(50);
// New port object
myPort = new Serial(this, Serial.list()[0], 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 );
ok = (int) (hand.getPosition().x);
myPort.write(ok);
println("Hand on Y: " + hand.getPosition().y );
// Determine ledPin according to mapped hand x position
delay(200);
}
}
void delay(int delay)
{
int time = millis();
while(millis()-time<=delay);
}
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”);
}
f. Cara Install Library
1. Buka Software Processing lalu Pilih Sketch -> Import Library -> add library
2. Search "leapmotion" lalu Pilih seperti di gambar berikut dan INSTALL
3. Library Siap digunakan
g. VIDEO HASILNYA