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