The IR.Reflect.Array class constructs an array of analog (digital arrays are not currently supported) reflectance sensors like the QTR-8A from Pololu.

Parameters

  • pins An array Numbers or Strings for the analog sensor pins.

  • emitter The pin where the emitter LED is attached. For these arrays, there is one pin that controls all of the emitters.

    var eyes = new five.IR.Reflect.Array({
      emitter: 13,
      pins: ["A0", "A1", "A2", "A3", "A4", "A5"]
    });
    
  • options An object of property parameters.

    PropertyTypeValue/DescriptionDefaultRequired
    pinsArray of Numbers, Strings["A*", ...]. The pins that the sensors are connected toyes
    emitterNumber, StringDigital Pin. The pin that the light emitter is connected toyes
    freqNumberMilliseconds. The frequency in ms of data events.25msno

Shape

Property NameDescriptionRead Only
idA user definable id value. Defaults to a generated uidNo
pinsThe pin addresses that the sensors are attached toNo
isOnAre the emitters on?Yes
isCalibratedDoes the array have calibration data?Yes
isOnLineIs the array currently tracking a line? isCalibrated===trueYes
sensorsAn array of sensor objects that represent each sensor in the array.Yes
calibrationThe current calibration data.Yes
rawAn array of raw values from all the sensors.Yes
valuesIf calibrated, an array of calibrated values (between 0 and 1000). If not calibrated, raw data (between 0 and 1023).Yes
lineIf calibrated, a value between 0 and (n-1)*1000+1. For example, 6 sensors will have a line between 0 and 5001.Yes

Component Initialization

Analog

new five.IR.Reflect.Array({
  emitter: 13,
  pins: ["A0", "A1", "A2"], // any number of pins
  freq: 25
});

Usage

var five = require("johnny-five"),
    board = new five.Board();

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

  // Create a new `reflectance` hardware instance.
  var eyes = new five.IR.Reflect.Array({
    emitter: 13,
    pins: ["A0", "A1", "A2"], // any number of pins
    freq: 25
  });

  eyes.on('data', function() {
    console.log( "Raw Values: ", this.raw );
  });

  eyes.on('line', function() {
    console.log( "Line Position: ", this.line);
  });

  eyes.enable();
});

API

  • enable() Turn the light emitters on.

    var eyes = new five.IR.Reflect.Array({
      emitter: 13,
      pins: ["A0", "A1"]
    });
    
    eyes.enable();
    
  • disable() turn the light emitters off

    var eyes = new five.IR.Reflect.Array({
      emitter: 13,
      pins: ["A0", "A1"]
    });
    
    eyes.disable();
    
  • calibrate() Read all of the sensors and store the min/max values. Used to calculate calibrated values and line values. You should call calibrate() multiple times.

    var eyes = new five.IR.Reflect.Array({
      emitter: 13,
      pins: ["A0", "A1"]
    });
    
    for (var i = 0; i < 100; i++) {
      eyes.calibrate();
    }
    
  • calibrateUntil(predicate) A convenience function that will call calibrate until a predicate function returns true. This allows you to decide when calibration is done. This trigger may be user input, time, or execution count. You decide.

    var eyes = new five.IR.Reflect.Array({
      emitter: 13,
      pins: ["A0", "A1"]
    });
    
    var calibrating = true;
    eyes.calibrateUntil(function() {
      return !calibrating;
    });
    
    // calibrate for one second
    setTimeout(function() { 
      calibrating = false; 
    }, 1000); 
    
  • loadCalibration(calibration) Prime the array with calibration data. This allows you to load calibration data from a file. You can get it from the device using the calibration after it has been calibrated.

    var eyes = new five.IR.Reflect.Array({
      emitter: 13,
      pins: ["A0", "A1"]
    });
    
    eyes.loadCalibration({
      min: [37, 39],
      max: [1010, 1015]
    });
    

Events

  • data The "data" event is fired as frequently as the user defined freq will allow in milliseconds. It includes an array of the RAW data from the sensors.

  • calibratedData The "calibratedData" event is fired as frequently as the user defined freq will allow in milliseconds. It also requires that the device has been calibrated. It includes an array of calibrated values between 0 and 1000.

  • line The "line" event is fired as frequently as the user defined freq will allow in milliseconds. It also requires that the devide has been calibrated. It is a single value between 0 and (n-1)*1000+1. An array with 6 sensors will yield a value between 0 and 5001.

0

Hi! The Johnny-Five community is building new projects every day. We made this newsletter to tell you about what's new, what's good, and what's next for Open Source robotics. Join us in exploring what we can make together.

Fork me on GitHub