Program a Arduino to output a sine wave / square wave

I’d does but it is way too slow to be used to generate a waveform in real time. What you need to do is to use it to generate a look up table in an array, and then play that out to the PWM. This will not result in you seeing a sin wave on the PWM output unless you change the frequency of the PWM to about 30 to 40 KHz and you put a restoration filter on the PWM output pin.

The look up table should be such that it consists of numbers between zero and 255. With sin(0.0) corresponding to 128.