How to use the johnny-five.Fn function in johnny-five

To help you get started, we’ve selected a few johnny-five examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jochasinga / firepot / pot / pot.js View on Github external
pot.on("data", function() {

    var self = this.value;
    // Print pot value 
    console.log(self);

    // Map dynamic color brightness to pot value
    // RED - MAGENTA - BLUE
    var redDec   = Math.round(five.Fn.map(self, offset, offset*2, 255, 0));
    var blueInc  = Math.round(five.Fn.map(self, 0, offset, 0, 255));
    // BLUE - CYAN - GREEN
    var blueDec  = Math.round(five.Fn.map(self, offset*3, offset*4, 255, 0));
    var greenInc = Math.round(five.Fn.map(self, offset*2, offset*3, 0, 255));
    // GREEN - YELLOW - RED
    var greenDec = Math.round(five.Fn.map(self, offset*5, offset*6, 255, 0));
    var redInc   = Math.round(five.Fn.map(self, offset*4, offset*5, 0, 255));

    // Adjusting color brightness conditionally based on 
    // the location of the pot output value.
    switch (true) {
      case (self > 0 && self <= offset):
        console.log("1st loop");
        ledArray[0].brightness(255);
        ledArray[2].brightness(blueInc);
        ledArray[1].brightness(0);
github AnnaGerber / node-ardx / code / CIRC09-code-photoresistor.js View on Github external
myPhotoresistor.on("data", function( err, value ) {
    // range of led brightness is 0 - 255
    var brightnessValue = five.Fn.constrain(five.Fn.map(value, 0, 900, 0, 255), 0, 255);
    myLed.brightness(brightnessValue);
  });
});
github xseignard / leapLamp / src / lib / joint.js View on Github external
scale(pos) {
		// if current hand/finger position is outside the tracked range
		// get the nearest tracked limit
		let constrainedPos;
		if (pos < this.minPos) constrainedPos = this.minPos;
		else if (pos > this.maxPos) constrainedPos = this.maxPos;
		else constrainedPos = pos;
		return Math.floor(
			five.Fn.map(
				constrainedPos,
				this.minPos,
				this.maxPos,
				this.servo.range[0],
				this.servo.range[1]
			)
		);
	}
}
github rwaldron / johnny-five / eg / arduino-starter-kit / keyboard.js View on Github external
sensor.on("change", function() {
    console.log(this.value);
    if (five.Fn.inRange(this.value, 1020, 1023)) {
      piezo.frequency(five.Piezo.Notes["c4"], 50);
    } else if (five.Fn.inRange(this.value, 990, 1010)) {
      piezo.frequency(five.Piezo.Notes["d4"], 50);
    } else if (five.Fn.inRange(this.value, 500, 520)) {
      piezo.frequency(five.Piezo.Notes["e4"], 50);
    } else if (five.Fn.inRange(this.value, 20, 40)) {
      piezo.frequency(five.Piezo.Notes["f4"], 50);
    } else {
      piezo.noTone();
    }
  });
});
github rwaldron / johnny-five / eg / TheArduinoStarterKit / Zoetrope.js View on Github external
sensor.on("change", function() {
    motorSpeed = five.Fn.map(this.value, 0, 1023, 0, 255);
    console.log(motorEnabled, motorDirection, motorSpeed);
    board.analogWrite(enablePin, motorEnabled ? motorSpeed : 0);
  });
github andrew / jquery-uk / nodecopter-hoodie / index.js View on Github external
leftYFlexSensor.on("read", function(err, value){
    var a= five.Fn.map(value, 100, 500, -90, 90);
    leftY = five.Fn.constrain(a, -80, 80);
    io.sockets.emit('leftY', { angle: leftY, value: value });
    move();
  });
  rightYFlexSensor.on("read", function(err, value){
github andrew / jquery-uk / nodecopter-hoodie / index.js View on Github external
leftZFlexSensor.on("read", function(err, value){
    var a= five.Fn.map(value, 550, 330, -60, 60);
    leftZ = five.Fn.constrain(a, -60, 60);
    io.sockets.emit('leftZ', { angle: leftZ, value: value });
    move();
  });
github rwaldron / johnny-five / eg / arduino-starter-kit / keyboard.js View on Github external
sensor.on("change", function() {
    console.log(this.value);
    if (five.Fn.inRange(this.value, 1020, 1023)) {
      piezo.frequency(five.Piezo.Notes["c4"], 50);
    } else if (five.Fn.inRange(this.value, 990, 1010)) {
      piezo.frequency(five.Piezo.Notes["d4"], 50);
    } else if (five.Fn.inRange(this.value, 500, 520)) {
      piezo.frequency(five.Piezo.Notes["e4"], 50);
    } else if (five.Fn.inRange(this.value, 20, 40)) {
      piezo.frequency(five.Piezo.Notes["f4"], 50);
    } else {
      piezo.noTone();
    }
  });
});
github tableflip / nodebot-workshop / exercises / robot_arm / solution / solution.js View on Github external
pot.on('change', function () {
    var position = five.Fn.map(this.value,
      0, 1023,
      0,  179
    )

    servo.to(position)
  })
github AnnaGerber / node-ardx / code / CIRC14-code-softpot.js View on Github external
function getRGB(hue) {
  var colors = [];
  var r = five.Fn.constrain(five.Fn.map(hue, 0, 512, 255, 0), 0, 255);
  var g = five.Fn.constrain(
        five.Fn.map(hue, 0, 512, 0, 255), 0, 255) -
      five.Fn.constrain(five.Fn.map(hue, 512, 1023, 0, 255),0,255);
  var b = five.Fn.constrain(five.Fn.map(hue, 512, 1023, 0, 255), 0, 255);
  colors[0] = r;
  colors[1] = g;
  colors[2] = b;
  return colors;
}

johnny-five

The JavaScript Robotics and Hardware Programming Framework. Use with: Arduino (all models), Electric Imp, Beagle Bone, Intel Galileo & Edison, Linino One, Pinoccio, pcDuino3, Raspberry Pi, Particle/Spark Core & Photon, Tessel 2, TI Launchpad and more!

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis