Nicholas Outram / Mbed OS Task352Solution
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);    //Outputs as an integer
00005 //BusIn binaryInput(D3, D4);          //Inputs as an integer
00006 DigitalIn SW1(D3);
00007 DigitalIn SW2(D4);
00008 
00009 //Main function
00010 int main() {
00011 
00012     //Create a variable to hold the bit pattern
00013     unsigned int u = 7;
00014 
00015     while(1) {
00016                  
00017         binaryOutput = u;    //Write to LEDs
00018            
00019         //TOGGLE all 3 bits in u
00020         u = u ^ 7;
00021            
00022         //Calculate the delay 
00023         int binaryInput = SW1 + (SW2 << 1);    
00024         double delay = (double)(binaryInput+1);
00025         wait(delay * 0.25);          //Wait
00026             
00027     } //end while(1)
00028 } //end main