High-end sensor: Ribbon potentiometer

The "soft pot" (shortened for soft potentiometer - ribbon potentiometer in French) is similar to the usual style potentiometer we see in exercise 8, with the difference being that it is flat, really thin and flexible and lacks a handle. A potentiometer is also known as a "variable resistance," and for a soft pot, the resistance supplied is determined by the pressure applied to it. This pressure can be applied with a finger, stylus or hard plastic. When pressed on various parts of the tape, the resistance ranges from 100 to 10 kOhm, which allows you to calculate the relative position of the tape. This can be used to track movement on softpot or "button style" spatial supports. In this scheme, it will be used to control the color of the RGB LED.

COMPONENTS

CIRCUIT DIAGRAM

Schéma du circuit

CIRCUIT INSTALLATION

Diagramme d'assemblage

CODE

You can find this code in CIRC-14-code-softpot.js

var five = require("johnny-five"),
    board, mySoftPot, myLed;

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;
}

board = new five.Board();

board.on("ready", function() {

  myLed = new five.Led.RGB([ 9, 10, 11 ]);

  mySoftPot = new five.Sensor({
    pin: "A0",
    freq: 250
  });

  mySoftPot.on("read", function( err, value ) {
    console.log("read value",value);
    var rgbColors = getRGB(value);
    myLed.color(rgbColors);
  });
});

EMERGENCY REPAIR

The LED remains black or is not the correct color

With four LED leads, so close together, it is sometimes easy to place one of them. Try to check that each pin is where it should be.

See red

The red diode among RGB LEDs may be slightly brighter than the other two. To make their colors more swayed, use a transistor with more ohms or adjust the red value in the code.

Strange results

The most likely reason is that you press the potentiometer several positions at once. This is normal and can actually be used to create some original results.

CODE EXTENSION

Similar buttons

Due to the way the tape potentiometer works, it can also be used to create arbitrary buttons. To do this, set a number of values ​ ​ corresponding to a separate button. Use the console to determine the desired values, and add a condition to check the interval of each "button" you want to create, for example:

if (value > minValue && value < maxValue) {
    button1Action();
} else if (value > minValue2 && value < maxValue2) {
    button2Action();
}

Ensuite recouvrez le ruban avec un schéma de bouton dessiné/imprimé.