aine

Dependencies:   mbed

Committer:
stanislashzc
Date:
Sat Feb 08 22:18:56 2014 +0000
Revision:
0:6048eae7eed6
cosine

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stanislashzc 0:6048eae7eed6 1
stanislashzc 0:6048eae7eed6 2 #include "mbed.h"
stanislashzc 0:6048eae7eed6 3 AnalogOut DA(PTE30);
stanislashzc 0:6048eae7eed6 4 AnalogIn AD(PTB0);
stanislashzc 0:6048eae7eed6 5
stanislashzc 0:6048eae7eed6 6 Serial pc(USBTX, USBRX); // tx, rx
stanislashzc 0:6048eae7eed6 7
stanislashzc 0:6048eae7eed6 8 float da;
stanislashzc 0:6048eae7eed6 9 float Amp = 2.0;
stanislashzc 0:6048eae7eed6 10 float w = 1.0;
stanislashzc 0:6048eae7eed6 11 float pi = 3.14159;
stanislashzc 0:6048eae7eed6 12
stanislashzc 0:6048eae7eed6 13 void callback() {
stanislashzc 0:6048eae7eed6 14 // Note: you need to actually read from the serial to clear the RX interrupt
stanislashzc 0:6048eae7eed6 15 //int AA;
stanislashzc 0:6048eae7eed6 16 //int ww;
stanislashzc 0:6048eae7eed6 17 printf("%c\n", pc.getc());
stanislashzc 0:6048eae7eed6 18 wait(0.5);
stanislashzc 0:6048eae7eed6 19 pc.printf("Input parameter A(<1.0):\n");
stanislashzc 0:6048eae7eed6 20 pc.scanf("%f", &Amp);
stanislashzc 0:6048eae7eed6 21 pc.printf("%f\n", Amp);
stanislashzc 0:6048eae7eed6 22 //Amp = (float)AA;
stanislashzc 0:6048eae7eed6 23 pc.printf("Input parameter w:\n");
stanislashzc 0:6048eae7eed6 24 pc.scanf("%f", &w);
stanislashzc 0:6048eae7eed6 25 pc.printf("%f\n", w);
stanislashzc 0:6048eae7eed6 26 //w = (float)ww;
stanislashzc 0:6048eae7eed6 27 }
stanislashzc 0:6048eae7eed6 28
stanislashzc 0:6048eae7eed6 29
stanislashzc 0:6048eae7eed6 30 int main(void) {
stanislashzc 0:6048eae7eed6 31
stanislashzc 0:6048eae7eed6 32
stanislashzc 0:6048eae7eed6 33 pc.attach(&callback);
stanislashzc 0:6048eae7eed6 34
stanislashzc 0:6048eae7eed6 35 while(1){
stanislashzc 0:6048eae7eed6 36 for (float i=0; i<360; i++) {
stanislashzc 0:6048eae7eed6 37 da = Amp*(sin(w*i/180*pi)*0.5+0.5);
stanislashzc 0:6048eae7eed6 38 DA.write(da);
stanislashzc 0:6048eae7eed6 39
stanislashzc 0:6048eae7eed6 40 pc.printf("%f ",da);
stanislashzc 0:6048eae7eed6 41
stanislashzc 0:6048eae7eed6 42
stanislashzc 0:6048eae7eed6 43 //AD.read()*3.3;
stanislashzc 0:6048eae7eed6 44 }
stanislashzc 0:6048eae7eed6 45 //wait(3.0);
stanislashzc 0:6048eae7eed6 46 }
stanislashzc 0:6048eae7eed6 47 }