Need Input on My Code For Unit 6 Lesson 7 Puzzle 15


#1

Can you tell me what I am doing wrong here?

soundSensor.setScale(0, 255);
lightSensor.setScale(0, 255);
var red = soundSensor.value;
var blue = lightSensor.value;
var green = tempSensor.F;
onBoardEvent(soundSensor, “data”, function(event) {
setProperty(“screen1”, “background-color”, rgb(red, green, blue, 1));
console.log(“sound”+ red);
});
Thanks,
Laura


#2

Sorry to leave you hanging here.
This looks like it should work once. So as you click run, the program should run and grab those sensor values and store them into your red, green, and blue variables. The problem resides in that no matter how many times the onBoardEvent is called, red, green, and blue still have the value that was set in them when the program started. You need to move those three lines into the onBoardEvent call.

soundSensor.setScale(0, 255);
lightSensor.setScale(0, 255);

onBoardEvent(soundSensor, "data", function(event) {

   var red = soundSensor.value;
   var blue = lightSensor.value;
   var green = tempSensor.F;

   setProperty("screen1", "background-color", rgb(red, green, blue, 1));
   console.log("sound"+ red);
});