Program to view the binary code returned from the 12 bit ADC

Dependencies:   mbed

main.cpp

Committer:
tgartlan
Date:
2018-03-14
Revision:
0:1ef96441fa7d

File content as of revision 0:1ef96441fa7d:

#include "mbed.h"
Serial pc(USBTX, USBRX);
AnalogOut Aout(p18);
AnalogIn Ain(p20);

DigitalOut myled(LED1);

int main() {
        unsigned short value = 0;
        //download test
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
        pc.printf("Ain value:-  ");
    while(1) {
        value = Ain.read_u16();
        value = value >>4;
        pc.printf("%d, ", value);  //send the float value to the PC  (Note this will introduce a delay, so be careful when you use serial comms
        wait(5);                    //delay of serial comms in this case is irrelevant
        
        pc.printf("%x, ", value);   //to print in hex format...might be useful
    }
}