Lab2 code

Dependencies:   mbed

main.cpp

Committer:
m0t0
Date:
2018-01-31
Revision:
0:7cab971d062d

File content as of revision 0:7cab971d062d:


#include "mbed.h"
Serial pc(USBTX, USBRX);
#if !DEVICE_ANALOGOUT
#error You cannot use this example as the AnalogOut is not supported on this device.
#else
AnalogOut my_output(PA_4);
#endif

#define PI        (3.141592653589793238462)
#define AMPLITUDE (1.0)    // x * 3.3V
#define PHASE     (PI * 1) // 2*pi is one period
#define RANGE     (0x7FFF)
#define OFFSET    (0x7FFF)

// Configuration for sinewave output
#define BUFFER_SIZE (360)

uint16_t buffer[BUFFER_SIZE];

void DCout(double Vout){
    double HEXval;
    HEXval = Vout * 19763.0;
    my_output.write_u16(HEXval);
}

char s [30];

void scan(){

int i = 0;


while(i<30){
    s[i] = pc.getc();
    if(s[i] != 0X0d){
        pc.putc(s[i]);
        i++;
        }
        else{
            break;
            }
        }

DCout(atof(s));


scan();


}


int main() {

    char p1 [] = "Enter Voltage";
    pc.printf("%s\n", p1);
    scan();
}