Hello, what is the easiest way to produce a sinus signal with Arduino Uno?
Ive read many threads about generating sinusodial waves and often there is mentionend to use pwm with a table for the values of sinus. Can anyone post and example code how to use this exactly? How do I get a sinussignal through pwm? How do I use the table? I
ve tried pwm myself with the following code
int LED = 10;
int dur= 100;
int M=10;
void setup()
{
Serial.begin(9600);
pinMode(LED,OUTPUT);
digitalWrite(LED,LOW);
}
void loop()
{
for(int i=0; i<M; i++)
{
if(i <= M/2){
pwm(i,M-i,dur); //rise LED's brightness from zero to Max.
}
else
{
pwm(M-i,i,dur); //dim LED to Min.
}
}
delay(dur);
}
void pwm(int active, int inactive, long duration)
{
long time = 0;
while(time < duration)
{
digitalWrite(LED,HIGH);
delay(active);
time += active;
digitalWrite(LED,LOW);
delay(inactive);
time += inactive;
}
}
and it seems to work fine to dim an LED to max and to zero again. But I think, this way, Im getting a triangular signal. So I think I need to map my linear signal somehow to a sine. I
m open to any (easier) solutions. (Espacially the one's mentioning a table).
I only want to drive some speakers with about 1Hz to 30Hz. So I need control over the frequency of the sine.