Output a sin wave to analog out pin

Dependencies:   mbed

main.cpp

Committer:
kzar
Date:
2018-10-16
Revision:
0:ee61df6b19ec

File content as of revision 0:ee61df6b19ec:

#include "mbed.h"
#include <cmath>
//Declare AnalogOut pin
AnalogOut apin(p18);

int main() {
    //Precompute Sin wave values and scale    
    float SinWave[20];
    float increment = 2*3.14/20;
    float arg = 0;
    for (int i = 0; i < 20; i++) {
        SinWave[i] = sin(arg)/2+0.5;
        arg = arg + increment;
    }
    //Output sinwave fovever
    while(1) {
        for (int i = 0; i < 20; i++) {
            apin = SinWave[i];
        }
    }
}