task411complete

Fork of Task411-FZ429 by University of Plymouth - Stages 1, 2 and 3

main.cpp

Committer:
martinjamesallen1991
Date:
2018-03-10
Revision:
2:6cf019cb87f5
Parent:
0:b2188dcbd1b1

File content as of revision 2:6cf019cb87f5:

#include "mbed.h"


//Global objects
DigitalOut Redled (D7);
DigitalOut Amberled (D6);
DigitalOut Greenled (D5);
DigitalIn SW1(D3);
DigitalIn SW2(D4);

AnalogIn AIN(A0);
float fVin = 0.0;

//Main function
int main() {


    while(1) {
        
        if (fVin >= 0.5f) 
{
    Redled = 1;
    Greenled = 0;
}
else
{
    Redled = 0;
    Greenled = 1; 
}
        
        //Read ADC         
        fVin = AIN;
        
        //Write to terminal
        printf("Analog input = %6.4f\n", fVin); //3 decimal places, fieldwidth=5
        
        //Wait
        wait(0.5);
            
    } //end while(1)
} //end main