Completed ready for demo- scan_mux_fun

Dependencies:   mbed

Fork of Microprocessors_Template by EECS397

main.cpp

Committer:
anr41
Date:
2018-02-08
Revision:
3:eb70e1c75e7f
Parent:
2:69ec832f181c

File content as of revision 3:eb70e1c75e7f:

/*******************************************************************************
*EECS397
*
*Assignment Name: Lab 3; Scan Mux Fun
*
*Author(s): Ashley Roberson, Michael Codega
*
*Purpose: Scan data of multiplexer & print data
*
*Last Modified: February 8, 2018
*
*******************************************************************************/
#include "mbed.h"
#define NUMCHANNELS 16

Serial pc(USBTX, USBRX);
char input;

void scanChannel(float *voltages);

float channelData[NUMCHANNELS];
BusOut muxSel(PC_6, PB_15, PB_13, PB_12);

AnalogIn muxOut(PB_1);



int main(void)
{

    while(1) {
        // wait for an input character to be rx'ed
        while(!pc.readable()) {
            ; // do nothing
        }

        input = pc.getc();

        // business logic:
        // scan 16 channels, store those values in array
        // print array
        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: %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();
    }
}