h

Dependencies:   mbed

Fork of HelloWorld by judo ~

Committer:
oopakhooo
Date:
Wed Nov 16 21:44:03 2016 +0000
Revision:
5:afabac4fce1b
Parent:
4:f0a11480f39f
serial params to interface

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:fb6bbc10ffa0 1 #include "mbed.h"
Judorunner 2:e2ae43e8acab 2 #include "PaceHeart.h"
oopakhooo 5:afabac4fce1b 3 #include "Hardware.h"
simon 0:fb6bbc10ffa0 4
oopakhooo 3:641eefd1110b 5 //DigitalOut output_pin_A(LED1);
simon 0:fb6bbc10ffa0 6
oopakhooo 5:afabac4fce1b 7 PaceHeart* Pacer = new PaceHeart();
oopakhooo 4:f0a11480f39f 8 DigitalOut led(LED1);
oopakhooo 5:afabac4fce1b 9 Serial pc(USBTX, USBRX);
oopakhooo 4:f0a11480f39f 10 void baud(int baudrate) {
oopakhooo 4:f0a11480f39f 11
oopakhooo 5:afabac4fce1b 12 pc.baud(baudrate);
oopakhooo 4:f0a11480f39f 13 }
oopakhooo 4:f0a11480f39f 14
Judorunner 2:e2ae43e8acab 15
simon 0:fb6bbc10ffa0 16 int main() {
oopakhooo 5:afabac4fce1b 17 baud(57600);
oopakhooo 5:afabac4fce1b 18 while(1){
oopakhooo 5:afabac4fce1b 19 Check_serial(pc,*Pacer);
oopakhooo 5:afabac4fce1b 20 }
oopakhooo 5:afabac4fce1b 21
oopakhooo 4:f0a11480f39f 22 /*
oopakhooo 3:641eefd1110b 23
oopakhooo 4:f0a11480f39f 24 AnalogOut aout(p18); //sets up pin 18 as an analogue output
oopakhooo 4:f0a11480f39f 25 AnalogueIn ain(p15); //sets up pin 15 and an analogue input
oopakhooo 4:f0a11480f39f 26
oopakhooo 4:f0a11480f39f 27 int main(){
oopakhooo 4:f0a11480f39f 28 aout=0.5; //sets output to 0.5*VCC
oopakhooo 4:f0a11480f39f 29 while(1){ //sets up a loop
oopakhooo 4:f0a11480f39f 30 if (ain>0.3){ //tests whether the input is above 0.3
oopakhooo 4:f0a11480f39f 31 aout=0; //sets the output to 0
oopakhooo 4:f0a11480f39f 32 }
oopakhooo 4:f0a11480f39f 33 aout = 0.5;
oopakhooo 4:f0a11480f39f 34 wait(1);
oopakhooo 4:f0a11480f39f 35 aout = 0;
oopakhooo 4:f0a11480f39f 36
oopakhooo 5:afabac4fce1b 37
oopakhooo 5:afabac4fce1b 38
oopakhooo 4:f0a11480f39f 39 }
oopakhooo 4:f0a11480f39f 40
oopakhooo 4:f0a11480f39f 41 sine wave output
oopakhooo 4:f0a11480f39f 42 const double pi = 3.141592653589793238462;
oopakhooo 4:f0a11480f39f 43 const double amplitude = 0.5f;
oopakhooo 4:f0a11480f39f 44 const double offset = 65535/2;
oopakhooo 4:f0a11480f39f 45 double rads = 0.0;
oopakhooo 4:f0a11480f39f 46 uint16_t sample = 0;
oopakhooo 4:f0a11480f39f 47
oopakhooo 4:f0a11480f39f 48 while(1) {
oopakhooo 4:f0a11480f39f 49 // sinewave output
oopakhooo 4:f0a11480f39f 50 for (int i = 0; i < 360; i++) {
oopakhooo 4:f0a11480f39f 51 rads = (pi * i) / 180.0f;
oopakhooo 4:f0a11480f39f 52 sample = (uint16_t)(amplitude * (offset * (cos(rads + pi))) + offset);
oopakhooo 4:f0a11480f39f 53 aout.write_u16(sample);
oopakhooo 4:f0a11480f39f 54 }
oopakhooo 4:f0a11480f39f 55 }
oopakhooo 4:f0a11480f39f 56 */
simon 0:fb6bbc10ffa0 57 }