lightSensor.setScale()

Category:Circuit Playground

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

Examples

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

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

Syntax

lightSensor.setScale(low, high);

Parameters

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

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