Completed ready for demo- scan_mux_fun

Dependencies:   mbed

Fork of Microprocessors_Template by EECS397

Revision:
2:69ec832f181c
Parent:
1:cff235122df8
Child:
3:eb70e1c75e7f
--- a/main.cpp	Sat Feb 03 17:49:10 2018 +0000
+++ b/main.cpp	Tue Feb 06 17:01:52 2018 +0000
@@ -1,27 +1,30 @@
 /*******************************************************************************
 *EECS397
 *
-*Assignment Name: Lab 3; Scan Mux
+*Assignment Name: Lab 3; Scan Mux Fun
 *
 *Author(s): Ashley Roberson, Michael Codega
 *
-*Purpose: Scans all 16 channels, stores those analog values in an array, and
-*         then prints values in array to serial console with each channel
-*         labeled when a key from the serial console is pressed.
+*Purpose:
 *
-*Last Modified: February 3, 2018
+*Last Modified: February 6, 2018
 *
 *******************************************************************************/
 #include "mbed.h"
+#define NUMCHANNELS 16
 
 Serial pc(USBTX, USBRX);
 char input;
 
-float channelData[16];
+void scanChannel(float *voltages);
+
+float channelData[NUMCHANNELS];
 BusOut muxSel(PC_6, PB_15, PB_13, PB_12);
 
 AnalogIn muxOut(PB_1);
 
+
+
 int main(void)
 {
 
@@ -36,21 +39,28 @@
         // business logic:
         // scan 16 channels, store those values in array
         // print array
-
-        for(int i = 0; i < 16; i++) {
-            // scan channels
-            muxSel = i;
-
-            wait(0.00001);
-
-            channelData[i] = muxOut.read();
-        }
-
-        for(int i = 0; i < 16; i++) {
+        scanChannel(channelData);
+        
+        pc.printf("Printing for Scan_Mux_Fun.\n");
+        
+        for(int i = 0; i < NUMCHANNELS; i++) {
 
             //print out
-            pc.printf("The channel data for %d is: %d\n", i, channelData[i]);
+            pc.printf("The channel data for %d is: %f\n", i, channelData[i] * 3.3f);
 
         }
     }
 }
+
+void scanChannel(float *voltages)
+{
+
+    for(int i = 0; i < NUMCHANNELS; i++) {
+        // scan channels
+        muxSel = i;
+
+        wait(0.00001);
+
+        voltages[i] = muxOut.read();
+    }
+}