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

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 //Global objects
00004 BusOut binaryOutput(D5, D6, D7);
00005 DigitalIn SW1(D4);
00006 
00007 //Function prototypes
00008 void waitForButtonPress();
00009 
00010 //Main function
00011 int main() {
00012 
00013     //Create a variable to hold the bit pattern
00014     unsigned int u;
00015 
00016     //Flash LED's to indicate the code is running
00017     binaryOutput = 7;
00018     wait(0.5);
00019     binaryOutput = 0;
00020 
00021     while(1) {
00022         
00023         u = 7;             //Set initial value 111
00024         binaryOutput = u;  //Show binary on LED's
00025         waitForButtonPress(); //Call function      
00026   
00027         //Use & to reset bit 1 
00028         u = u & 5;          //AND with binary 101
00029         binaryOutput = u;   
00030         waitForButtonPress();   
00031                                
00032         //Modify u with & to reset bit 2 to a 0
00033         //WRITE CODE HERE
00034         binaryOutput = u;   
00035         waitForButtonPress();                          
00036 
00037 
00038         //Modify u with & to reset bit 0 to a 0
00039         //WRITE CODE HERE
00040         binaryOutput = u;   
00041         waitForButtonPress();   
00042         
00043     } //end while(1)
00044 } //end main
00045 
00046 
00047 void waitForButtonPress() {
00048     while (SW1 == 0);
00049     wait(0.25);
00050     while (SW1 == 1);
00051 }