Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
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 //Main Loop 00022 while(1) { 00023 00024 u = 0; //Set initial value 00025 binaryOutput = u; //Show binary on LED's 00026 waitForButtonPress(); //Call function 00027 00028 //Here is the first - use | to set bit 1 00029 u = u | 2; //OR with binary 010 00030 binaryOutput = u; 00031 waitForButtonPress(); 00032 00033 //Modify u with the | to set bit 2 00034 //WRITE CODE HERE 00035 00036 binaryOutput = u; 00037 waitForButtonPress(); 00038 00039 00040 //Modify u with the | to set bit 0 00041 //WRITE CODE HERE 00042 00043 binaryOutput = u; 00044 waitForButtonPress(); 00045 00046 } //end while(1) 00047 } //end main 00048 00049 //This is known as a C function. 00050 //This saves a lot of code repetition 00051 void waitForButtonPress() { 00052 while (SW1 == 0); 00053 wait(0.25); 00054 while (SW1 == 1); 00055 }
Generated on Fri Jul 22 2022 17:56:25 by
1.7.2