Scan_Mux_fun2 in progress
Dependencies: mbed
Fork of Microprocessors_Template by
Revision 3:3bdbf15ff26b, committed 2018-02-08
- Comitter:
- anr41
- Date:
- Thu Feb 08 16:31:51 2018 +0000
- Parent:
- 2:e76a4b45d3a1
- Commit message:
- Completed
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Feb 06 17:02:29 2018 +0000 +++ b/main.cpp Thu Feb 08 16:31:51 2018 +0000 @@ -5,13 +5,14 @@ * *Author(s): Ashley Roberson, Michael Codega * -*Purpose: +*Purpose: Read analog data off multiplexer, determine if changed,& print results * -*Last Modified: February 6, 2018 +*Last Modified: February 8, 2018 * *******************************************************************************/ #include "mbed.h" #define NUMCHANNELS 16 +#define TOLERANCE 10 Serial pc(USBTX, USBRX); char input; @@ -28,7 +29,9 @@ 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()) { @@ -40,14 +43,18 @@ // business logic: // scan 16 channels, store those values in array // print array - scanChannel(channelData); - + 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\n", i, channelData[i] * 3.3f); + 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); } } @@ -68,11 +75,13 @@ bool checkChange(float *reference, float *voltages, float tolerance) { - scanChannel(voltages); + //scanChannel(voltages); for (int i = 0; i < NUMCHANNELS; i++) { - if (voltages[i] - reference[i] > tolerance) - return false; - else if(reference[i] - voltages[i] > tolerance) - return false; + //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 true; + return false; +} \ No newline at end of file