Generiranje sinus funkcije preko ticker-a
Fork of VU_meter_Predavec by
Revision 1:874889ddde0e, committed 2015-12-03
- Comitter:
- dpredavec
- Date:
- Thu Dec 03 18:38:22 2015 +0000
- Parent:
- 0:ea4e3eefa035
- Commit message:
- Sinus funkcija - Predavec
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ea4e3eefa035 -r 874889ddde0e main.cpp --- a/main.cpp Thu Dec 03 18:05:15 2015 +0000 +++ b/main.cpp Thu Dec 03 18:38:22 2015 +0000 @@ -1,49 +1,16 @@ -#include "mbed.h" // Predavec - VU LED vjezba -Serial pc(USBTX, USBRX); -AnalogIn Ain(p20); - -DigitalOut led1(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); -DigitalOut led4(LED4); - -float ADCdata; - -int main() { - pc.printf("ADC Data Values... \n\r"); - while (1) { - ADCdata=Ain; - pc.printf("%f \n\r",ADCdata); - if (Ain <= 0.2){ - led1 = 0; - led2 = 0; - led3 = 0; - led4 = 0; - } - if ((Ain>0.2)&&(Ain<=0.4)){ - led1 = 1; - led2 = 0; - led3 = 0; - led4 = 0; - } - if ((Ain>0.4)&&(Ain<=0.6)){ - led1 = 1; - led2 = 1; - led3 = 0; - led4 = 0; - } - if ((Ain>0.6)&&(Ain<=0.8)){ - led1 = 1; - led2 = 1; - led3 = 1; - led4 = 0; - } - if ((Ain>0.8)&&(Ain<=1.0)){ - led1 = 1; - led2 = 1; - led3 = 1; - led4 = 1; - } - wait (0.01); - } -} +#include "mbed.h" // Predavec - sinus funkcija +#define PI 3.14159265359 +#define PPI 2*PI +Ticker TS; +AnalogOut DA18(p18); +float y, f=50, kut = 0; +int T=50; +void sinus () { + y = 0.5*sin(kut) + 0.5; // generiranje funkcije sinus + DA18.write(y); // slanje funkcije na izlaz + kut += PPI * f * T * 1e-6; + if (kut > PPI) { kut = kut - PPI; } + } +int main () { + TS.attach_us(&sinus,T); + }