task411complete

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 
00004 //Global objects
00005 DigitalOut Redled (D7);
00006 DigitalOut Amberled (D6);
00007 DigitalOut Greenled (D5);
00008 DigitalIn SW1(D3);
00009 DigitalIn SW2(D4);
00010 
00011 AnalogIn AIN(A0);
00012 float fVin = 0.0;
00013 
00014 //Main function
00015 int main() {
00016 
00017 
00018     while(1) {
00019         
00020         if (fVin >= 0.5f) 
00021 {
00022     Redled = 1;
00023     Greenled = 0;
00024 }
00025 else
00026 {
00027     Redled = 0;
00028     Greenled = 1; 
00029 }
00030         
00031         //Read ADC         
00032         fVin = AIN;
00033         
00034         //Write to terminal
00035         printf("Analog input = %6.4f\n", fVin); //3 decimal places, fieldwidth=5
00036         
00037         //Wait
00038         wait(0.5);
00039             
00040     } //end while(1)
00041 } //end main