#include <math.h>;
#define PI 3.1415926535897932384626433832795
int counterValue = 0x80; //defines the frequency of the PWM cycle, and the vertical resolution of the "analog out" from the PWM
unsigned long pwmFreq = 16000000/(counterValue+1); //16Mhz clock
unsigned long targetFreq = 1000; //Hz, this is the frequency of the sine wave desired
unsigned long numSamples = pwmFreq/targetFreq;
float sineWave[];
void fillSineArray();
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // Any baud rate should work
Serial.println(pwmFreq);
Serial.println(numSamples);
fillSineArray();
}
void loop() {
// put your main code here, to run repeatedly:
}
void fillSineArray(){
for(unsigned short i = 0; i < numSamples;i++){
sineWave[i]=(sin(float(i)/numSamples*2*PI)+1)/2;
Serial.println(int(sineWave[i]*counterValue));
}
}