Nicholas Outram / Mbed OS Task422Solution
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #define kRED    (1 << 2)    //4
00004 #define kYELLOW (1 << 1)    //2
00005 #define kGREEN  (1 << 0)    //1
00006 
00007 //Global objects
00008 BusOut binaryOutput(D5, D6, D7);    
00009 DigitalIn SW1(D3);
00010 DigitalIn SW2(D4);
00011 
00012 AnalogIn POT_ADC_In(A0);
00013 AnalogIn LDD_ADC_In(A1);
00014 float fPOT, fLDR = 0.0;
00015 
00016 //Main function
00017 int main() {
00018     
00019     while(1) {
00020         unsigned op = 0u;
00021         
00022         //Read ADC
00023         fPOT = POT_ADC_In;  //Threshold
00024         fLDR = LDD_ADC_In;  //Light reading
00025         
00026         //Write to terminal
00027         printf("POT = %6.4f\tLDR = %6.4f\n", fPOT, fLDR);
00028         
00029         if (fLDR < 0.1f) {
00030             op = kRED | kYELLOW | kGREEN;    
00031         } else if (fLDR < 0.15f) {
00032             op = kYELLOW | kRED;     
00033         } else if (fLDR < 0.2f) {
00034             op = kRED;
00035         } else {
00036             op = 0;    
00037         }
00038 
00039         //Write to port
00040         binaryOutput = op;
00041         
00042         //Wait
00043         wait(0.1);
00044         
00045     } //end while(1)
00046 } //end main