When using timer as Tone() can I still use second pin as PWM for LED?

Or at least as ordinary I/O pin?
I'm working on project where my UNO is literally out of any pins. I would like to avoid using expander like CD4021.

I know that frequency would be same for both pins, but can the PWM be different for both of them?

Do you know that the analogue pins can be used as digital pins as well. Just call them A0, A1.... and so on and use the digital read and write as well.

Using the tone library uses one of the timers, I think timer2, as an interrupt so you won’t be able to use that timer’s PWM pin. But all other functions of that pin read and write will work.

know that frequency would be same for both pins, but can the PWM be different for both of them?

Yes each timer has two pins associated with it and each pin has its own chip that controls the duty cycle.

I know about analog I/O's. I already use them.

So if I get it right, the program won't let me use tone() and PWM at the same time?

But logically it can be "hard programmed". Because PWM chips are spared. Am I right?

But all other functions of that pin read and write will work.

You mean of the same pin or the other one associated with the same timer?

At least thanks a lot for reply, you helped me a lot!

Because PWM chips are spared. Am I right?

nor sure what you mean by "spared" in this context.

You mean of the same pin or the other one associated with the same timer?

I mean if a pin is associated with a timer, as shown by the ~ symbol next to it, the pin does not use that timer in anyway unless you are trying to get PWM out of it. For all other uses it remains exactly the same as any other pin.

On the Uno, Tone() uses Timer2, and output is on the A pin (D11). Mode is CTC to OCR2A with a toggle on compare match at the top.

You should be able to set an output compare for the B pin using the Timer2 register settings. You should refer to a AT328 data sheet.

Source code for tone() is at

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\Tone.cpp