You are reading a single comment by @JumJum and its replies. Click here to read the full conversation.
  • In this small project, a HC-SR04 is used to support simple gestures.
    There is already some information around ST04 in Espruino Documentation
    First of all an gesture object needs to be created

    var g = new gesture(A0,A1);  //for more information about pins, take a look at http://www.espruino.com/HC-SR04
    

    Next the distance from SR04 is splitted into named areas.

    g.addArea("bottom",10,20);  //First parameter is name of the area, next are start and end of area in cm
    g.addArea("middle",30,40);
    g.addArea("top",50,60);
    

    Last not least assign callbacks for each type of gesture, which returns area, type of event and distance from SR04

    g.setCallback("enter",function(a,t,d){co­nsole.log(a,t,d);});
    g.setCallback("leave",function(a,t,d){co­nsole.log(a,t,d);});
    g.setCallback("click",function(a,t,d){co­nsole.log(a,t,d);});
    g.setCallback("move",function(a,t,d,p){c­onsole.log(a,t,d,p);});
    

    Simply test this by moving your hand above SR04.
    enter is fired after moving the hand into an area
    leave is fired after leaving an area in whatever direction
    click is fired if entering and leaving happen for the same are
    move is fired if your hand moves inside an area and returns one more parameter, giving position in area in percent.
    Some training will help to move your hand correctly inside an area, for example to hold your fingers close to each other finger(including thumb :-). For staying inside an area a coloured piece of paper will be helpful

    Attached code gives the source for gesture-object.


    1 Attachment

About

Avatar for JumJum @JumJum started