SEARCH
TOOLBOX
LANGUAGES
modified on 14 August 2014 at 15:02 ••• 30,389 views

04-03 SinusoidWave

From Manuals

Revision as of 15:02, 14 August 2014 by Support (Talk | contribs)
Jump to: navigation, search

This example outputs a sine wave on the DAC output.

/*Program Example 4.3: Sine wave on DAC output. View on oscilloscope
                                                                           */
#include "mbed.h"
AnalogOut Aout(DAC0);
float i;

int main()
{
    while(1)  {
        for (i=0; i<2; i=i+0.05f) {
            Aout=0.5f+0.5f*sin(i*3.14159f);  // Compute the sine value, + half the range
            wait(.001);                      // Controls the sine wave period
        }
    }
}