Nicholas Outram
/
Task421
Task 4.2.1
main.cpp@1:d8372070fc1b, 2017-07-13 (annotated)
- Committer:
- noutram
- Date:
- Thu Jul 13 14:53:21 2017 +0000
- Revision:
- 1:d8372070fc1b
- Parent:
- 0:01bd097f996a
updated for mbed-os 5.5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:01bd097f996a | 1 | #include "mbed.h" |
noutram | 0:01bd097f996a | 2 | |
noutram | 0:01bd097f996a | 3 | #define kRED (1 << 2) //4 |
noutram | 0:01bd097f996a | 4 | #define kYELLOW (1 << 1) //2 |
noutram | 0:01bd097f996a | 5 | #define kGREEN (1 << 0) //1 |
noutram | 0:01bd097f996a | 6 | #define kALL (kRED | kYELLOW | kGREEN) |
noutram | 0:01bd097f996a | 7 | |
noutram | 0:01bd097f996a | 8 | //Global objects |
noutram | 0:01bd097f996a | 9 | BusOut binaryOutput(D5, D6, D7); |
noutram | 0:01bd097f996a | 10 | DigitalIn SW1(D3); |
noutram | 0:01bd097f996a | 11 | DigitalIn SW2(D4); |
noutram | 0:01bd097f996a | 12 | |
noutram | 0:01bd097f996a | 13 | AnalogIn POT_ADC_In(A0); |
noutram | 0:01bd097f996a | 14 | AnalogIn LDD_ADC_In(A1); |
noutram | 0:01bd097f996a | 15 | float fPOT, fLDR = 0.0; |
noutram | 0:01bd097f996a | 16 | |
noutram | 0:01bd097f996a | 17 | //Main function |
noutram | 0:01bd097f996a | 18 | int main() { |
noutram | 0:01bd097f996a | 19 | |
noutram | 0:01bd097f996a | 20 | while(1) { |
noutram | 0:01bd097f996a | 21 | |
noutram | 0:01bd097f996a | 22 | //Read ADC |
noutram | 0:01bd097f996a | 23 | fPOT = POT_ADC_In; |
noutram | 0:01bd097f996a | 24 | fLDR = LDD_ADC_In; |
noutram | 0:01bd097f996a | 25 | |
noutram | 0:01bd097f996a | 26 | //Write to terminal |
noutram | 0:01bd097f996a | 27 | printf("POT = %6.4f\tLDR = %6.4f\n", fPOT, fLDR); |
noutram | 0:01bd097f996a | 28 | |
noutram | 0:01bd097f996a | 29 | if (fLDR > fPOT) { |
noutram | 0:01bd097f996a | 30 | binaryOutput = 0; //Binary 000 |
noutram | 0:01bd097f996a | 31 | } else { |
noutram | 0:01bd097f996a | 32 | binaryOutput = kALL; //Binary 111 |
noutram | 0:01bd097f996a | 33 | } |
noutram | 0:01bd097f996a | 34 | |
noutram | 0:01bd097f996a | 35 | //Wait |
noutram | 0:01bd097f996a | 36 | wait(0.1); |
noutram | 0:01bd097f996a | 37 | |
noutram | 0:01bd097f996a | 38 | } //end while(1) |
noutram | 0:01bd097f996a | 39 | } //end main |