MTU COMP71004 Summer 2021 / Mbed 2 deprecated lect6_1_analogIn

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kinii
Date:
Tue Jul 13 12:33:57 2021 +0000
Parent:
0:e36fb7e4cd89
Commit message:
first commit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e36fb7e4cd89 -r 66c794ac87fa main.cpp
--- a/main.cpp	Thu Jul 01 18:20:29 2021 +0000
+++ b/main.cpp	Tue Jul 13 12:33:57 2021 +0000
@@ -1,14 +1,20 @@
 #include "mbed.h"
 
-AnalogIn p1(p19);
+AnalogIn p1(p17);       //different pin - i.e. unconnected
 AnalogOut o1(p18);
 
 int main() {
     while(1) {
-        float p1_float = p1;    // read pot1 value
-        float p1_volts = p1_float * 3.3;    // convert analog value to voltage
-        printf("float: %f volts: %f \r\n",p1_float, p1_volts);
-        wait(1);  
-
+        for(int i=0; i<10; i++){
+            printf("for loop i=%d \r\n", i);
+            o1 = i/10;    // applying analoginput...
+            
+            // physically connect a wire btween p1 and o1
+            wait(1);
+            float p1_float = p1;    // read pot1 value
+            float p1_volts = p1_float * 3.3;    // convert analog value to voltage
+            printf("float: %f volts: %f \r\n",p1_float, p1_volts);
+            wait(3);  
+        }   
     }
 }