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 while(1) { 00022 00023 u = 0; //Set initial value 0 00024 binaryOutput = u; //Show binary on LED's 00025 waitForButtonPress(); //Call function 00026 00027 //Use & to toggle bit 0 00028 u = u ^ 1; //XOR with binary 001 00029 binaryOutput = u; 00030 waitForButtonPress(); 00031 00032 //Toggle bit 1 00033 //WRITE CODE HERE 00034 binaryOutput = u; 00035 waitForButtonPress(); 00036 00037 00038 //Toggle bit 2 00039 //WRITE CODE HERE 00040 binaryOutput = u; 00041 waitForButtonPress(); 00042 00043 //Toggle bits 0 and 2 00044 //WRITE CODE HERE 00045 binaryOutput = u; 00046 waitForButtonPress(); 00047 00048 //Toggle all bits 00049 //WRITE CODE HERE 00050 binaryOutput = u; 00051 waitForButtonPress(); 00052 00053 //Toggle all bits 00054 //WRITE CODE HERE 00055 binaryOutput = u; 00056 waitForButtonPress(); 00057 00058 } //end while(1) 00059 } //end main 00060 00061 00062 void waitForButtonPress() { 00063 while (SW1 == 0); 00064 wait(0.25); 00065 while (SW1 == 1); 00066 }
Generated on Tue Jul 26 2022 08:28:07 by
1.7.2