sensor
sample_hardware.cpp@4:d884f14069c6, 2017-11-22 (annotated)
- Committer:
- noutram
- Date:
- Wed Nov 22 15:18:12 2017 +0000
- Revision:
- 4:d884f14069c6
- Parent:
- 3:768d30157488
- Child:
- 5:58ba1a6dbf60
Error codes using LEDs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:6f9f2e93a0be | 1 | #include "mbed.h" |
noutram | 0:6f9f2e93a0be | 2 | #include "sample_hardware.hpp" |
noutram | 0:6f9f2e93a0be | 3 | |
noutram | 0:6f9f2e93a0be | 4 | #define RED_DONE 1 |
noutram | 0:6f9f2e93a0be | 5 | #define YELLOW_DONE 2 |
noutram | 0:6f9f2e93a0be | 6 | |
noutram | 0:6f9f2e93a0be | 7 | //Digital outputs |
noutram | 0:6f9f2e93a0be | 8 | DigitalOut onBoardLED(LED1); |
noutram | 0:6f9f2e93a0be | 9 | DigitalOut redLED(PE_15); |
noutram | 0:6f9f2e93a0be | 10 | DigitalOut yellowLED(PB_10); |
noutram | 0:6f9f2e93a0be | 11 | DigitalOut greenLED(PB_11); |
noutram | 0:6f9f2e93a0be | 12 | |
noutram | 0:6f9f2e93a0be | 13 | //Inputs |
noutram | 0:6f9f2e93a0be | 14 | DigitalIn onBoardSwitch(USER_BUTTON); |
noutram | 0:6f9f2e93a0be | 15 | DigitalIn SW1(PE_12); |
noutram | 0:6f9f2e93a0be | 16 | DigitalIn SW2(PE_14); |
noutram | 0:6f9f2e93a0be | 17 | //Serial pc(USBTX, USBRX); |
noutram | 2:24eb98cf2376 | 18 | AnalogIn adcIn(PA_0); |
noutram | 0:6f9f2e93a0be | 19 | |
noutram | 3:768d30157488 | 20 | |
noutram | 0:6f9f2e93a0be | 21 | //POWER ON SELF TEST |
noutram | 0:6f9f2e93a0be | 22 | void post() |
noutram | 0:6f9f2e93a0be | 23 | { |
noutram | 0:6f9f2e93a0be | 24 | //POWER ON TEST (POT) |
noutram | 3:768d30157488 | 25 | puts("ALL LEDs should be blinking"); |
noutram | 0:6f9f2e93a0be | 26 | for (unsigned int n=0; n<10; n++) { |
noutram | 0:6f9f2e93a0be | 27 | redLED = 1; |
noutram | 0:6f9f2e93a0be | 28 | yellowLED = 1; |
noutram | 0:6f9f2e93a0be | 29 | greenLED = 1; |
noutram | 0:6f9f2e93a0be | 30 | wait(0.05); |
noutram | 0:6f9f2e93a0be | 31 | redLED = 0; |
noutram | 0:6f9f2e93a0be | 32 | yellowLED = 0; |
noutram | 0:6f9f2e93a0be | 33 | greenLED = 0; |
noutram | 0:6f9f2e93a0be | 34 | wait(0.05); |
noutram | 3:768d30157488 | 35 | } |
noutram | 3:768d30157488 | 36 | |
noutram | 3:768d30157488 | 37 | //Output the switch states (hold them down to test) |
noutram | 3:768d30157488 | 38 | printf("SW1: %d\tSW2: %d\n\r", SW1.read(), SW2.read()); |
noutram | 3:768d30157488 | 39 | |
noutram | 3:768d30157488 | 40 | //Output the ADC |
noutram | 3:768d30157488 | 41 | printf("ADC: %f\n\r", adcIn.read()); |
noutram | 4:d884f14069c6 | 42 | } |
noutram | 4:d884f14069c6 | 43 | |
noutram | 4:d884f14069c6 | 44 | void errorCode(ELEC350_ERROR_CODE err) |
noutram | 4:d884f14069c6 | 45 | { |
noutram | 4:d884f14069c6 | 46 | switch (err) { |
noutram | 4:d884f14069c6 | 47 | case OK: |
noutram | 4:d884f14069c6 | 48 | greenLED = 1; |
noutram | 4:d884f14069c6 | 49 | wait(1.0); |
noutram | 4:d884f14069c6 | 50 | greenLED = 0; |
noutram | 4:d884f14069c6 | 51 | return; |
noutram | 4:d884f14069c6 | 52 | case FATAL: |
noutram | 4:d884f14069c6 | 53 | while(1) { |
noutram | 4:d884f14069c6 | 54 | redLED = 1; |
noutram | 4:d884f14069c6 | 55 | wait(0.1); |
noutram | 4:d884f14069c6 | 56 | redLED = 0; |
noutram | 4:d884f14069c6 | 57 | wait(0.1); |
noutram | 4:d884f14069c6 | 58 | } |
noutram | 4:d884f14069c6 | 59 | }; |
noutram | 0:6f9f2e93a0be | 60 | } |