Martin Allen
/
Task411-FZ429INIT
task411complete
Fork of Task411-FZ429 by
main.cpp@2:6cf019cb87f5, 2018-03-10 (annotated)
- Committer:
- martinjamesallen1991
- Date:
- Sat Mar 10 02:26:20 2018 +0000
- Revision:
- 2:6cf019cb87f5
- Parent:
- 0:b2188dcbd1b1
added led
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:b2188dcbd1b1 | 1 | #include "mbed.h" |
noutram | 0:b2188dcbd1b1 | 2 | |
martinjamesallen1991 | 2:6cf019cb87f5 | 3 | |
noutram | 0:b2188dcbd1b1 | 4 | //Global objects |
martinjamesallen1991 | 2:6cf019cb87f5 | 5 | DigitalOut Redled (D7); |
martinjamesallen1991 | 2:6cf019cb87f5 | 6 | DigitalOut Amberled (D6); |
martinjamesallen1991 | 2:6cf019cb87f5 | 7 | DigitalOut Greenled (D5); |
noutram | 0:b2188dcbd1b1 | 8 | DigitalIn SW1(D3); |
noutram | 0:b2188dcbd1b1 | 9 | DigitalIn SW2(D4); |
noutram | 0:b2188dcbd1b1 | 10 | |
noutram | 0:b2188dcbd1b1 | 11 | AnalogIn AIN(A0); |
noutram | 0:b2188dcbd1b1 | 12 | float fVin = 0.0; |
noutram | 0:b2188dcbd1b1 | 13 | |
noutram | 0:b2188dcbd1b1 | 14 | //Main function |
noutram | 0:b2188dcbd1b1 | 15 | int main() { |
noutram | 0:b2188dcbd1b1 | 16 | |
noutram | 0:b2188dcbd1b1 | 17 | |
noutram | 0:b2188dcbd1b1 | 18 | while(1) { |
noutram | 0:b2188dcbd1b1 | 19 | |
martinjamesallen1991 | 2:6cf019cb87f5 | 20 | if (fVin >= 0.5f) |
martinjamesallen1991 | 2:6cf019cb87f5 | 21 | { |
martinjamesallen1991 | 2:6cf019cb87f5 | 22 | Redled = 1; |
martinjamesallen1991 | 2:6cf019cb87f5 | 23 | Greenled = 0; |
martinjamesallen1991 | 2:6cf019cb87f5 | 24 | } |
martinjamesallen1991 | 2:6cf019cb87f5 | 25 | else |
martinjamesallen1991 | 2:6cf019cb87f5 | 26 | { |
martinjamesallen1991 | 2:6cf019cb87f5 | 27 | Redled = 0; |
martinjamesallen1991 | 2:6cf019cb87f5 | 28 | Greenled = 1; |
martinjamesallen1991 | 2:6cf019cb87f5 | 29 | } |
martinjamesallen1991 | 2:6cf019cb87f5 | 30 | |
noutram | 0:b2188dcbd1b1 | 31 | //Read ADC |
noutram | 0:b2188dcbd1b1 | 32 | fVin = AIN; |
noutram | 0:b2188dcbd1b1 | 33 | |
noutram | 0:b2188dcbd1b1 | 34 | //Write to terminal |
noutram | 0:b2188dcbd1b1 | 35 | printf("Analog input = %6.4f\n", fVin); //3 decimal places, fieldwidth=5 |
noutram | 0:b2188dcbd1b1 | 36 | |
noutram | 0:b2188dcbd1b1 | 37 | //Wait |
noutram | 0:b2188dcbd1b1 | 38 | wait(0.5); |
noutram | 0:b2188dcbd1b1 | 39 | |
noutram | 0:b2188dcbd1b1 | 40 | } //end while(1) |
noutram | 0:b2188dcbd1b1 | 41 | } //end main |