I discovered today that there's a problem with the email I wrote to my professor a few days ago. It turns out that adding a delay() is not necessary to make the speaker sound.
But I don't understand why the code I wrote back then doesn't work without the delay.
368e29193d6d464463301cd13cf68234.mp4
Today, I and my friends tried to distinguish the difference between adding delay and not adding delay.
Less than 400 or greater than 900 are negative values, and then negative values are converted to absolute values and mapped to 0-255.
This might explain why the light bulb dims and then brightens.
In addition, we found that connecting resistors of different resistance values in series behind the sensor will make the sensor have different sensitivities.
phototransistor