Page 209 - ARM Based Microcontroller Projects Using MBED
P. 209
8.20 PROJECT 16—DIGITAL VOLTMETER 195
/*************************************************************************
VOLTMETER
=========
This is a voltmeter program. Input analog voltage is applied to analog
input ADC1/0 (GPIO pin PA_0) of the Nucleo-F411RE development board.
The program reads and displays the analog voltage in millivolts on the
PC screen
Author: Dogan Ibrahim
Date : August 2018
File : Voltmeter
**************************************************************************/
#include "mbed.h"
Serial MyPC(USBTX, USBRX);
AnalogIn ain(PA_0);
// Clear the screen
//
void clrscr()
{
char clrscr[] = {0x1B, '[', '2' , 'J',0};
MyPC.printf(clrscr);
}
//
// Home the cursor
//
void homescr()
{
char homescr[] = {0x1B, '[' , 'H' , 0};
MyPC.printf(homescr);
}
//
// Goto specified line and column
//
void gotoscr(int line, int column)
{
char scr[] = {0x1B, '[', 0x00, ';' ,0x00, 'H', 0};
scr[2] = line;
scr[4] = column;
MyPC.printf(scr);
}
int main()
{
double mV;
clrscr(); // Clear the screen
homescr(); // Home teh cursor
MyPC.printf("\n\rVOLTMETER"); // Heading
MyPC.printf("\n\r=========");
FIG. 8.57 Program listing.
(Continued)