Sine Wave Function?

Hello

New to using the Spark here - I want to vary the amplitude of an LED is a sinusoidal manner through one of the analogue ports, but it seems there is no sine function to work with that I can find.

How do I generate a sine wave, say based upon the timer? Will be straightforward once I know how to find that function!

Thanks

Hi @PaulR

In C the sine function is in

#include <math.h>

So you need to include that. I believe that sin(x) in traditional C is only available for double datatype, but in more modern compilers you can use double, float, and long double.

PaulR, you can also use a sine lookup table (256 bytes in size) if you want faster control but your application may not need it. There are plenty of Arduino examples to cull code from. :smile:

Reminds me of how I made a Mood lamp ny hand using a PIC chip… wooooo. Good old days! :smiley:

Thanks, the include dealt with that. Appreciate the suggestion of the lookup table, speed should be fine with the function.

2 Likes