4. map()

In that setting, we played around with the tone value and arbitrarily chose to have a range close to 440Hz.
If we would like to widen the range to a few octaves, then we would need to somehow adjust the reading value to what a pre-defined frequency range.

One way to do this is using the map() function.

map() re-maps a number from one range to another. That is, a value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.
The map() function automatically scales one sensor value and converts it to another range of values.
map(value, fromLow, fromHigh, toLow, toHigh)

In this example we are going to convert ambient light readings to the range of 220Hz (100Hz is the minimum speaker frequency) to 880Hz.

We will change this line:
int pitch = 200 + reading / 4;
to one like this:
int pitch = map(reading, 700, 1023, 220, 880);

Try to debug the sketch using the SerialMonitor and adjust your map() parameters according to the ambient light readings you take and the aesthetic result you want to achieve.