dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * Version of the Analog test,
00003  * Intended for use by devices which
00004  * don't have analog out.
00005  *
00006  * Connect 'control' to pin 21 of an mbed LPC1768
00007  * Connect 'analogInput' to pin 18 of an mbed LPC1768
00008  * Connect 'TX/RX' to pins 27 and 28 of an mbed LPC1768
00009  *
00010  * Upload:
00011 */
00012 #include "test_env.h"
00013 
00014 #define ERROR_TOLERANCE 0.05
00015 
00016 #if defined(TARGET_LPC1114)
00017 
00018 AnalogIn analogInput(dp4);
00019 DigitalOut control(dp5);
00020 DigitalOut indicator(LED1);
00021 
00022 #else
00023 
00024 #error [NOT_SUPPORTED] This test is not supported on this target
00025 
00026 #endif
00027 
00028 uint8_t successes = 0;
00029 
00030 int main() {
00031     control = 0;
00032 
00033     for (int i = 0; i < 10; i++) {
00034         // Read value,
00035         float expectedValue = i * 0.1;
00036         float value = analogInput.read();
00037 
00038         if (value > expectedValue + ERROR_TOLERANCE || value < expectedValue - ERROR_TOLERANCE) {
00039             // Failure.
00040             printf("ERROR (out:%.4f) - (in:%.4f) = (%.4f)"NL, expectedValue, value, fabs(expectedValue - value));
00041         }
00042         else {
00043             printf("OK    (out:%.4f) - (in:%.4f) = (%.4f)"NL, out_value, in_value, diff);
00044             successes++;
00045         }
00046 
00047         control = 1;
00048         indicator = 1;
00049         wait(0.1);
00050         control = 0;
00051         indicator = 0;
00052     }
00053 
00054     if (successes > 8) {
00055         notify_success(true);
00056     }
00057     else {
00058         notify_success(false);
00059     }
00060 }