weeb grammers
/
Assignment2
something
Fork of HelloWorld by
main.cpp
- Committer:
- weebgrammers
- Date:
- 2016-11-14
- Revision:
- 5:45d58f8a5912
- Parent:
- 4:f0a11480f39f
File content as of revision 5:45d58f8a5912:
#include "mbed.h" #include "PaceHeart.h" //DigitalOut output_pin_A(LED1); PaceHeart* Pacer = new PaceHeart; DigitalOut led(LED1); Serial s(USBTX, USBRX); void baud(int baudrate) { s.baud(baudrate); } int main() { /* baud(57600); s.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"); while(1) { char c = s.getc(); pc.putc(pc.getc()); //echoes back input if((c == 'u')) { led = !led; } if((c == 'd')) { led = 0; } }*/ Pacer-> pace_A(); /* PwmOut out(PTA0); pulse width thingy PwmIn in(PTD1); float pe,pw,ds; // set the PwmOut in seconds out.pulsewidth(2); out.period(4); while (true) { pe= in.period(); pw= in.pulsewidth(); ds= in.dutycycle(); pc.printf("A period= %f, pulsewidth= %f, duty cycle= %f\n\r",pe, pw, ds); wait(1); } AnalogOut aout(p18); //sets up pin 18 as an analogue output AnalogueIn ain(p15); //sets up pin 15 and an analogue input int main(){ aout=0.5; //sets output to 0.5*VCC while(1){ //sets up a loop if (ain>0.3){ //tests whether the input is above 0.3 aout=0; //sets the output to 0 } aout = 0.5; wait(1); aout = 0; } sine wave output const double pi = 3.141592653589793238462; const double amplitude = 0.5f; const double offset = 65535/2; double rads = 0.0; uint16_t sample = 0; while(1) { // sinewave output for (int i = 0; i < 360; i++) { rads = (pi * i) / 180.0f; sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset); aout.write_u16(sample); } } */ }