Quantcast
Channel: Arduino - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 747

Combine Processing+Arduino+Leapmotion

$
0
0

Hello, I'm combining leapmotion, processing and arduino, I use the leapmotion for processing library, and the way I do is if leapmotion detected hand, send '1' to serial port which is for arduino, and if there's no hand, send'0'. After receive 1, arduino turn on the relay, receive 0 turn off. but I failed and I can't figure out which part is the mistake, here is my 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()[2]; //change the 0 to a 1 or 2 etc. to match your port
          myPort = new Serial(this, portName, 9600);
        }
        void draw() {
          int number=0;
          for (Hand hand : leap.getHands() ) {
            number=hand.countFingers();
          }
          println(number);

          if (number!= 0)
          {
            myPort.write('1');         //send a 1
            println("1");
          } else
          {                           //otherwise
            myPort.write('0');          //send a 0
          }


        }

Arduino :

    char val; // Data received from the serial port
    int ledPin = 13; // Set the pin to digital I/O 13

    void setup() {
      pinMode(ledPin, OUTPUT);
      Serial.begin(9600);
    }
    void loop() {
      if (Serial.available())
      { // If data is available to read,
        val = Serial.read();
        }

      if (val == '1')
      { // If 1 was received
        digitalWrite(ledPin, HIGH);
      } else {
        digitalWrite(ledPin, LOW);
      }
      delay(10);
    }

Viewing all articles
Browse latest Browse all 747

Latest Images

Trending Articles



Latest Images