lightSensor.setScale()

Category:Circuit

Creates a scale for the value of the lightSensor to follow.

Examples

onBoardEvent(lightSensor, "data", function(event) {
  lightSensor.setScale(0, 255);
  var light1 = lightSensor.value;
  lightSensor.setScale(100, 255);
  var light2 = lightSensor.value;
  lightSensor.setScale(0, 255);
  var light3 = lightSensor.value;
  setProperty("screen1", "background-color", rgb(light1,light2,light3));
});

var redness;
lightSensor.setScale(0, 255);
timedLoop(100, function() {
  redness = Math.round(lightSensor.value);
  setProperty("screen1", "background-color", rgb(redness, 0, 0));
});

Syntax

lightSensor.setScale(low, high);

Parameters

Name Type Required? Description
high number The high value to end the scale at.
low number The low value to start the scale at.

Found a bug in the documentation? Let us know at documentation@code.org