How to change the range of PWM value

Hello there! I'm doing some project using kinect + processing + arduino. Fyi I am so so new with this software. Here i have code that control the brightness of led using hand movement that i get from internet. But the problem is i don understand where to initialize the first value in frame that construct by processing?

import processing.serial.*; import java.util.Map; import java.util.Iterator; import SimpleOpenNI.*; import processing.serial.*; SimpleOpenNI context; Serial myPort;

int handVecListSize = 20; Map<Integer,ArrayList> handPathList = new HashMap<Integer,ArrayList>(); color[] userClr = new color[]{ color(255,0,0), color(0,255,0), color(0,0,255), color(255,255,0), color(255,0,255), color(0,255,255) };

void setup() { // frameRate(200); size(640,480); context = new SimpleOpenNI(this);

if(context.isInit() == false) { println("Can't init SimpleOpenNI, maybe the camera is not connected!"); exit(); return;
}

// enable depthMap generation context.enableDepth();

// disable mirror context.setMirror(true);

// enable hands + gesture generation //context.enableGesture(); context.enableHand(); context.startGesture(SimpleOpenNI.GESTURE_WAVE); String portName = Serial.list()[0]; // This gets the first port on your computer. myPort = new Serial(this, portName, 9600);

// set how smooth the hand capturing should be //context.setSmoothingHands(.5); }

void draw() { // update the cam context.update();

image(context.depthImage(),0,0);

// draw the tracked hands if(handPathList.size() > 0)
{
Iterator itr = handPathList.entrySet().iterator();
while(itr.hasNext()) { Map.Entry mapEntry = (Map.Entry)itr.next(); int handId = (Integer)mapEntry.getKey(); ArrayList vecList = (ArrayList)mapEntry.getValue(); PVector p; PVector p2d = new PVector();

    stroke(userClr[ (handId - 1) % userClr.length ]);
    noFill(); 
    strokeWeight(1);        
    Iterator itrVec = vecList.iterator(); 
    beginShape();
      while( itrVec.hasNext() ) 
      { 
        p = (PVector) itrVec.next(); 

        context.convertRealWorldToProjective(p,p2d);
        vertex(p2d.x,p2d.y);
      }
    endShape();   

    stroke(userClr[ (handId - 1) % userClr.length ]);
    strokeWeight(4);
    p = vecList.get(0);
    context.convertRealWorldToProjective(p,p2d);
    point(p2d.x,p2d.y);

      myPort.write('S');

// Send the value of the mouse's x-position myPort.write(int(255* p2d .x/width)); // Send the value of the mouse's y-position myPort.write(int(255* p2d.y/height));

}        

} }

// ----------------------------------------------------------------- // hand events

void onNewHand(SimpleOpenNI curContext,int handId,PVector pos) { println("onNewHand - handId: " + handId + ", pos: " + pos);

ArrayList vecList = new ArrayList(); vecList.add(pos);

handPathList.put(handId,vecList); }

void onTrackedHand(SimpleOpenNI curContext,int handId,PVector pos) { //println("onTrackedHand - handId: " + handId + ", pos: " + pos );

ArrayList vecList = handPathList.get(handId); if(vecList != null) { vecList.add(0,pos); if(vecList.size() >= handVecListSize) // remove the last point vecList.remove(vecList.size()-1); }
}

void onLostHand(SimpleOpenNI curContext,int handId) { println("onLostHand - handId: " + handId); handPathList.remove(handId); }

// ----------------------------------------------------------------- // gesture events

void onCompletedGesture(SimpleOpenNI curContext,int gestureType, PVector pos) { println("onCompletedGesture - gestureType: " + gestureType + ", pos: " + pos);

int handId = context.startTrackingHand(pos); println("hand stracked: " + handId); }

// ----------------------------------------------------------------- // Keyboard event void keyPressed() {

switch(key) { case ' ': context.setMirror(!context.mirror()); break; case '1': context.setMirror(true); break; case '2': context.setMirror(false); break; } }

void onRecognizeGesture(String strGesture, PVector idPosition, PVector endPosition) { // SimpleOpenNI.GESTURE_HAND_RAISE //endPosition context.endGesture(SimpleOpenNI.GESTURE_HAND_RAISE ); context.startTrackingHand(endPosition); // context.startGesture(SimpleOpenNI.GESTURE_WAVE); }

Answers

Sign In or Register to comment.