Reads all the ADC ports available on the Nucleo F303K8 and prints the results in Value Read, Volts and 16 bit unsigned short.
Reads all ADC available on Nucleo-F303K8 and sends results to PC over USB UART.
main.cpp
- Committer:
- joeata2wh
- Date:
- 2016-03-19
- Revision:
- 0:fa185766e039
- Child:
- 1:a368dd17f04c
File content as of revision 0:fa185766e039:
/* Example of Reading all the ADC pins available on the Nucleo_F303K8. by Joseph Ellsworth CTO A2WH - Free for all but no warranty, no promises */ #include "mbed.h" // Initialize a pins to perform analog input and digital output fucntions AnalogIn aA7(PA_2); AnalogIn aA6(PA_7); AnalogIn aA5(PA_6); AnalogIn aA4(PA_5); AnalogIn aA3(PA_4); AnalogIn aA2(PA_3); AnalogIn aA1(PA_1); AnalogIn aA0(PA_0); AnalogIn aB0(PB_0); AnalogIn aB1(PB_1); DigitalOut myled(LED1); const float voltMeterARef = 3.3; float readPrint(AnalogIn ain, char *label) { float tval = ain.read(); float volts = tval * voltMeterARef; float perc = tval * 100.0; unsigned short tvalu16 = ain.read_u16 (); printf("adc %s R=%3.3f V=%3.3f%% U16=%u\r\n",label, tval, volts, tvalu16); return tval; } int main() { while(1) { myled = !myled; // toggle led readPrint(aA7, "PA_7"); readPrint(aA6, "PA_6"); readPrint(aA5, "PA_5"); readPrint(aA4, "PA_4"); readPrint(aA3, "PA_3"); readPrint(aA2, "PA_2"); readPrint(aA1, "PA_1"); readPrint(aA0, "PA_0"); readPrint(aB0, "PB_0"); readPrint(aB1, "PB_1"); printf("\r\n\r\n"); wait(7.0); } }