Declare an array the size you want, then walk through the array computing the sine of that position, storing it in the array. I've got code handy that does this anyways for my synthesizer and I was curious just how different a PWM driven LED would would look if it was driven by a sine wave than if it was driven by a simple for() loop.
Conclusion: not worth the effort to write the code but if you're still interested here you go.
#define SINSIZE 255
#define TWOPIOVERSINSIZE (PI*2)/(float)SINSIZE
#define LEDPIN 10
unsigned char sins_of_our_fathers[SINSIZE];
void setup()
{
Serial.begin(9600);
pinMode(10, HIGH);
Serial.print("Precomputing sine wave.");
for(unsigned char i=0;i<SINSIZE;i++)
{
sins_of_our_fathers[i] = (128.0*sin( (float)i*TWOPIOVERSINSIZE) ) + 127;
Serial.print(".");
}
Serial.println("Done.");
}
void loop()
{
for(unsigned char i=0;i<SINSIZE;i++)
{
analogWrite(LEDPIN, sins_of_our_fathers[i]);
delay(50);
Serial.print("SIN: ");
Serial.println( sins_of_our_fathers[i] , DEC);
}
for(unsigned char i=0;i<255;i++)
{
analogWrite(LEDPIN, i);
delay(50);
Serial.print("NOTSIN: ");
Serial.println( i , DEC);
}
}