Hi guys, I have been trying to code using Leap Motion and Arduino to control servo and led using Processing 3.5.4, (both codes attached below), and when I run the processing code, I got black screen. Did I miss anything? I got no error whatsoever when running the code (I think the codes are working fine, yet the black screen and the servo wont move)
// Processing code
import processing.serial.*;
import de.voidplus.leapmotion.*;
LeapMotion leap;
Serial myPort;
void setup() {
leap = new LeapMotion(this);
println(Serial.list());
myPort = new Serial(this,"COM3", 9600);
}
void draw() {
background(0);
for (Hand hand : leap.getHands()) {
pushMatrix();
float handSize = hand.getSphereRadius();
int handSize2 = int(handSize);
myPort.write(handSize2);
println(handSize2);
popMatrix();
}
}
#include <Servo.h>
// Arduino code is available to download - link below the video.
Servo m1;
int pos = 0;
int val;
int led = 3; // the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
m1.attach(A0);
}
// the loop routine runs over and over again forever:
void loop() {
if (Serial.available() == '\n') { // Check if there is a new message
val= Serial.read();
// 1st fragment
/*if (val<60) {
for (pos = 175; pos >= 60; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
m1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if (val>60) {
for (pos = 60; pos <= 175; pos += 1) { // goes from 180 degrees to 0 degrees
m1.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
*/
// 2nd fragment
val = map(val, 30, 165, 50, 175); // map(value, fromLow, fromHigh, toLow, toHigh)
m1.write(val);
}
}