Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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);
});
});
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]
)
);
}
}
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();
}
});
});
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);
});
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){
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();
});
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();
}
});
});
pot.on('change', function () {
var position = five.Fn.map(this.value,
0, 1023,
0, 179
)
servo.to(position)
})
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;
}