Examen pratique info S5

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 AnalogOut an_Out(p18);
00004 Ticker timer;
00005 
00006 void Sinus(void);
00007 void calculateSinus();
00008 
00009 int temp = 2500;
00010 float sins[5000];
00011 
00012 int main()
00013 {
00014     calculateSinus();
00015 
00016     timer.attach(&Sinus, 0.000002);
00017 
00018     while(1) {
00019         wait(1);
00020     }
00021 
00022 }
00023 
00024 void calculateSinus()
00025 {
00026     int a;
00027     for(a = 0;a<5000;a++)
00028     {
00029         sins[a] = cos(a/5000.0*2.0*3.1416)/2+.5;
00030     }
00031 }
00032 
00033 
00034 void Sinus (void)
00035 {
00036     an_Out.write(sins[temp++]);
00037     
00038     if(temp == 5000)
00039         temp =0;
00040 }