Can we combine the last two programs to create a musical instrument that changes the note it's playing depending on how much light it see? Using variables is useful and we'll use them more later, but for this, let's see how small we can make the program. We need to get measure the light level and play a note for a specific duration. Start with an empty loop and drop in a tone block (this time, grab one with a duration (milliseconds) socket). Change the pin# to 3 and the duration to 100. Finally, replace the frequency block with an analog pin block and set the pin to 0. That's it. Now you have a Theremin.
Looking at the code, it's just as simple. Again, use the tone command we used before, this time drop the analogRead(A0) into the frequency parameter.
void setup()
{
}
void loop()
{
tone(3, analogRead(A0), 100);
}
Try covering the light sensor to hear different notes. Can you make it sound like a police siren with this?