Preliminary main mbed library for nexpaq development
libraries/tests/mbed/analog_pot/main.cpp@1:d96dbedaebdb, 2016-11-04 (annotated)
- Committer:
- nexpaq
- Date:
- Fri Nov 04 20:54:50 2016 +0000
- Revision:
- 1:d96dbedaebdb
- Parent:
- 0:6c56fb4bc5f0
Removed extra directories for other platforms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nexpaq | 0:6c56fb4bc5f0 | 1 | #include "mbed.h" |
nexpaq | 0:6c56fb4bc5f0 | 2 | #include "test_env.h" |
nexpaq | 0:6c56fb4bc5f0 | 3 | |
nexpaq | 0:6c56fb4bc5f0 | 4 | #if !DEVICE_ANALOGIN |
nexpaq | 0:6c56fb4bc5f0 | 5 | #error [NOT_SUPPORTED] AnalogIn not supported |
nexpaq | 0:6c56fb4bc5f0 | 6 | #endif |
nexpaq | 0:6c56fb4bc5f0 | 7 | |
nexpaq | 0:6c56fb4bc5f0 | 8 | #if defined(TARGET_VK_RZ_A1H) |
nexpaq | 0:6c56fb4bc5f0 | 9 | AnalogIn pot1(P1_8); |
nexpaq | 0:6c56fb4bc5f0 | 10 | AnalogIn pot2(P1_9); |
nexpaq | 0:6c56fb4bc5f0 | 11 | #else |
nexpaq | 0:6c56fb4bc5f0 | 12 | AnalogIn pot1(A0); |
nexpaq | 0:6c56fb4bc5f0 | 13 | AnalogIn pot2(A1); |
nexpaq | 0:6c56fb4bc5f0 | 14 | #endif |
nexpaq | 0:6c56fb4bc5f0 | 15 | |
nexpaq | 0:6c56fb4bc5f0 | 16 | #define TEST_ITERATIONS 20 |
nexpaq | 0:6c56fb4bc5f0 | 17 | #define MEASURE_MIN 0.01 |
nexpaq | 0:6c56fb4bc5f0 | 18 | |
nexpaq | 0:6c56fb4bc5f0 | 19 | int main(void) { |
nexpaq | 0:6c56fb4bc5f0 | 20 | MBED_HOSTTEST_TIMEOUT(10); |
nexpaq | 0:6c56fb4bc5f0 | 21 | MBED_HOSTTEST_SELECT(default_auto); |
nexpaq | 0:6c56fb4bc5f0 | 22 | MBED_HOSTTEST_DESCRIPTION(AnalogIn potentiometer test); |
nexpaq | 0:6c56fb4bc5f0 | 23 | MBED_HOSTTEST_START("analog_pot"); |
nexpaq | 0:6c56fb4bc5f0 | 24 | |
nexpaq | 0:6c56fb4bc5f0 | 25 | bool result = false; |
nexpaq | 0:6c56fb4bc5f0 | 26 | float val1, val2; |
nexpaq | 0:6c56fb4bc5f0 | 27 | |
nexpaq | 0:6c56fb4bc5f0 | 28 | for (int i = 0; i < TEST_ITERATIONS; i++) { |
nexpaq | 0:6c56fb4bc5f0 | 29 | val1 = pot1.read(); |
nexpaq | 0:6c56fb4bc5f0 | 30 | val2 = pot2.read(); |
nexpaq | 0:6c56fb4bc5f0 | 31 | |
nexpaq | 0:6c56fb4bc5f0 | 32 | const char *succes_str = val1 > MEASURE_MIN || val2 > MEASURE_MIN ? "[OK]" : "[FAIL]"; |
nexpaq | 0:6c56fb4bc5f0 | 33 | result = result || (val1 > MEASURE_MIN || val2 > MEASURE_MIN); |
nexpaq | 0:6c56fb4bc5f0 | 34 | printf("Pot values %f, %f\r\n", val1, val2); |
nexpaq | 0:6c56fb4bc5f0 | 35 | wait(0.001); |
nexpaq | 0:6c56fb4bc5f0 | 36 | } |
nexpaq | 0:6c56fb4bc5f0 | 37 | MBED_HOSTTEST_RESULT(result); |
nexpaq | 0:6c56fb4bc5f0 | 38 | } |