weeb grammers / Mbed 2 deprecated Assignment2

Dependencies:   mbed

Fork of HelloWorld by Vincent Cheung

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "PaceHeart.h"
00003 
00004 //DigitalOut output_pin_A(LED1);
00005 
00006 PaceHeart* Pacer = new PaceHeart;
00007 DigitalOut led(LED1);
00008 Serial s(USBTX, USBRX);
00009 void baud(int baudrate) {
00010     
00011     s.baud(baudrate);
00012 }
00013     
00014 
00015 int main() {
00016     /*
00017     baud(57600);
00018      s.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");
00019     while(1) {
00020       char c = s.getc();
00021       pc.putc(pc.getc()); //echoes back input
00022         if((c == 'u')) {
00023             
00024             led = !led;
00025         }
00026         if((c == 'd')) {
00027             led = 0;
00028         } 
00029     }*/
00030     Pacer-> pace_A();
00031        /* PwmOut out(PTA0);        pulse width thingy    
00032         PwmIn  in(PTD1);            
00033         float pe,pw,ds;
00034 
00035     // set the PwmOut in seconds
00036         out.pulsewidth(2);
00037         out.period(4);
00038 
00039         while (true) {
00040         pe= in.period();
00041         pw= in.pulsewidth();
00042         ds= in.dutycycle();
00043         pc.printf("A period= %f, pulsewidth= %f, duty cycle= %f\n\r",pe, pw, ds);
00044 
00045         wait(1);
00046         }
00047         
00048         AnalogOut aout(p18);  //sets up pin 18 as an analogue output
00049         AnalogueIn ain(p15);  //sets up pin 15 and an analogue input
00050  
00051         int main(){
00052              aout=0.5;  //sets output to 0.5*VCC
00053             while(1){    //sets up a loop
00054              if (ain>0.3){   //tests whether the input is above 0.3
00055             aout=0;  //sets the output to 0
00056       }
00057       aout = 0.5;
00058       wait(1);
00059       aout = 0;
00060       
00061    }
00062    
00063            sine wave output
00064            const double pi = 3.141592653589793238462;
00065             const double amplitude = 0.5f;
00066             const double offset = 65535/2;
00067             double rads = 0.0;
00068             uint16_t sample = 0;
00069             
00070             while(1) {
00071                 // sinewave output
00072                 for (int i = 0; i < 360; i++) {
00073                     rads = (pi * i) / 180.0f;
00074                     sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset);
00075                     aout.write_u16(sample);
00076                 }
00077             }
00078     */
00079 }