Scan_Mux_fun2 in progress
Dependencies: mbed
Fork of Microprocessors_Template by
main.cpp
- Committer:
- anr41
- Date:
- 2018-02-08
- Revision:
- 3:3bdbf15ff26b
- Parent:
- 2:e76a4b45d3a1
File content as of revision 3:3bdbf15ff26b:
/******************************************************************************* *EECS397 * *Assignment Name: Lab 3; Scan Mux Fun2 * *Author(s): Ashley Roberson, Michael Codega * *Purpose: Read analog data off multiplexer, determine if changed,& print results * *Last Modified: February 8, 2018 * *******************************************************************************/ #include "mbed.h" #define NUMCHANNELS 16 #define TOLERANCE 10 Serial pc(USBTX, USBRX); char input; void scanChannel(float *voltages); bool checkChange(float *reference, float *voltages, float tolerance); float channelData[NUMCHANNELS]; BusOut muxSel(PC_6, PB_15, PB_13, PB_12); AnalogIn muxOut(PB_1); int main(void) { float reference[NUMCHANNELS]; float voltages[NUMCHANNELS]; scanChannel(reference); 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(voltages); bool hasChanged = checkChange(reference, voltages, TOLERANCE); if (hasChanged) pc.printf("Data has changed!\n"); else pc.printf("No Change!\n"); pc.printf("Printing for Scan_Mux_Fun2.\n"); for(int i = 0; i < NUMCHANNELS; i++) { //print out pc.printf("The channel data for %d is: %f The reference data for %d is: %f\n", i, voltages[i] * 3.3f, i, reference[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(); } } bool checkChange(float *reference, float *voltages, float tolerance) { //scanChannel(voltages); for (int i = 0; i < NUMCHANNELS; i++) { //pc.printf("Voltage: %f Reference: %f\n", voltages[i], reference[i]); if ((voltages[i] - reference[i]) > tolerance * .001) return true; else if((reference[i] - voltages[i]) > tolerance * .001) return true; } return false; }