First laboratory uses each of the five routines with your modifications. These routines illustrate digital output, PWM output, and Analog input and output.

Revision:
67:9015fa015c73
Parent:
66:0a43d8aeeb76
Child:
68:61bde79fc489
--- a/main.cpp	Tue Jun 26 17:52:09 2018 +0000
+++ b/main.cpp	Thu Aug 23 13:49:20 2018 +0000
@@ -1,14 +1,27 @@
 #include "mbed.h"
 
-DigitalOut led1(LED1);
+Serial pc(USBTX, USBRX);
+
+// Initialize a pins to perform analog and digital output functions
+AnalogOut aout(p18);
+AnalogIn ain(p20);
 
-// main() runs in its own thread in the OS
-int main() {
-    while (true) {
-        led1 = !led1;
-        wait(0.02);
-        led1 = !led1;
-        wait(0.02);
+char text[128];
+float voltage;
+// Adjust VCC to get best scaling
+float VCC1=3.292;
+float VCC2=3.292;
+
+int main(void){
+   while (1) {
+        pc.printf("Please enter an output voltage\n\r");
+        pc.scanf("%s", text);
+        voltage = atof(text);
+        pc.printf("Voltage output is %f\n\r", voltage);
+        // set the output value to be voltage/VCC
+        aout = voltage/VCC1;
+        // read the output voltage
+        pc.printf("Voltage read is %f\n\r", ain*VCC2);
     }
 }