Nicholas Outram / Mbed OS Task431
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 #define kALL (kRED | kYELLOW | kGREEN)
00007 
00008 //Global objects
00009 BusOut binaryOutput(D5, D6, D7);    
00010 DigitalIn SW1(D3);
00011 DigitalIn SW2(D4);
00012 
00013 AnalogIn POT_ADC_In(A0);
00014 AnalogIn LDD_ADC_In(A1);
00015 
00016 float fPOT, fLDR = 0.0;
00017 
00018 //Main function
00019 int main() {
00020     
00021     while(1) {
00022         
00023         //Read ADC
00024         fPOT = POT_ADC_In;
00025         fLDR = LDD_ADC_In;
00026         
00027         //TODO:
00028         //Calculate the average of both fPOT and fLDR, then write to the terminal
00029         
00030         //Write to terminal
00031         printf("POT = %6.4f\tLDR = %6.4f\n", fPOT, fLDR);
00032         
00033         if (fLDR > fPOT) {
00034             binaryOutput = 0;      //Binary 000    
00035         } else {
00036             binaryOutput = kALL;   //Binary 111
00037         }
00038         
00039         //Wait
00040         wait(0.1);
00041         
00042     } //end while(1)
00043 } //end main