Hi,

I've created a working air pollution alarm prototype using an NodeMCU V2 CP2102 ESP8266.

The machine receives API data from http://aqicn.org/ in the form of an integer between ~20-600.
The tone function then sonifies this integer by converting the API data ('result_aqi) into hertz (speaker vibration/time).

Tone functions basics
tone( pin number, frequency in hertz, duration in milliseconds);

My tone function
tone( pin number, result_aqi, duration in milliseconds)

``````tone(14, result_aqi, 100);
delay(1000);
``````

Ex: If the machine receives an API data of 440 ('result_aqi'), the tone function outputs 440 speaker vibrations/time, which we perceive as A4 (shown in this table here: Frequencies of Musical Notes, A4 = 440 Hz)

QUESTION:

• Can I add an ADSR (attack, decay, sustain, release) to the tone function? For example, increase the attack of the sound so it slowly ascends in volume?
• Can I take 'result_aqi' and apply a logarithimic scale so that small changes in 'results_aqi' (such as 1 or 5 or 19) can result in perceptibly noticeable changes in pitch?

The regular Arduino doesn't have a DAC (no true-analog output). tone() just puts-out square waves and you get what you get.

You can make some changes to tone and volume together if you make your own pulse function and vary the duty cycle, but that's rather limited.

Can I add an ADSR (attack, decay, sustain, release) to the tone function?

No.

Can I take 'result_aqi' and apply a logarithimic scale so that small changes in 'results_aqi' (such as 1 or 5 or 19) can result in perceptibly noticeable changes in pitch?

Yes, just write a function like the map function only use a log scaling factor. Do you know what constants do you want to use?