Task 3.4.2

Committer:
noutram
Date:
Thu Jul 13 14:50:24 2017 +0000
Revision:
1:965090fe87b9
Parent:
0:62df7f96de34
updated for mbed-os 5.5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:62df7f96de34 1 #include "mbed.h"
noutram 0:62df7f96de34 2
noutram 0:62df7f96de34 3 //Global objects
noutram 0:62df7f96de34 4 BusOut binaryOutput(D5, D6, D7);
noutram 0:62df7f96de34 5 DigitalIn SW1(D4);
noutram 0:62df7f96de34 6
noutram 0:62df7f96de34 7 //Function prototypes
noutram 0:62df7f96de34 8 void waitForButtonPress();
noutram 0:62df7f96de34 9
noutram 0:62df7f96de34 10 //Main function
noutram 0:62df7f96de34 11 int main() {
noutram 0:62df7f96de34 12
noutram 0:62df7f96de34 13 //Create a variable to hold the bit pattern
noutram 0:62df7f96de34 14 unsigned int u;
noutram 0:62df7f96de34 15
noutram 0:62df7f96de34 16 //Flash LED's to indicate the code is running
noutram 0:62df7f96de34 17 binaryOutput = 7;
noutram 0:62df7f96de34 18 wait(0.5);
noutram 0:62df7f96de34 19 binaryOutput = 0;
noutram 0:62df7f96de34 20
noutram 0:62df7f96de34 21 while(1) {
noutram 0:62df7f96de34 22
noutram 0:62df7f96de34 23 u = 7; //Set initial value 111
noutram 0:62df7f96de34 24 binaryOutput = u; //Show binary on LED's
noutram 0:62df7f96de34 25 waitForButtonPress(); //Call function
noutram 0:62df7f96de34 26
noutram 0:62df7f96de34 27 //Use & to reset bit 1
noutram 0:62df7f96de34 28 u = u & 5; //AND with binary 101
noutram 0:62df7f96de34 29 binaryOutput = u;
noutram 0:62df7f96de34 30 waitForButtonPress();
noutram 0:62df7f96de34 31
noutram 0:62df7f96de34 32 //Modify u with & to reset bit 2 to a 0
noutram 0:62df7f96de34 33 //WRITE CODE HERE
noutram 0:62df7f96de34 34 binaryOutput = u;
noutram 0:62df7f96de34 35 waitForButtonPress();
noutram 0:62df7f96de34 36
noutram 0:62df7f96de34 37
noutram 0:62df7f96de34 38 //Modify u with & to reset bit 0 to a 0
noutram 0:62df7f96de34 39 //WRITE CODE HERE
noutram 0:62df7f96de34 40 binaryOutput = u;
noutram 0:62df7f96de34 41 waitForButtonPress();
noutram 0:62df7f96de34 42
noutram 0:62df7f96de34 43 } //end while(1)
noutram 0:62df7f96de34 44 } //end main
noutram 0:62df7f96de34 45
noutram 0:62df7f96de34 46
noutram 0:62df7f96de34 47 void waitForButtonPress() {
noutram 0:62df7f96de34 48 while (SW1 == 0);
noutram 0:62df7f96de34 49 wait(0.25);
noutram 0:62df7f96de34 50 while (SW1 == 1);
noutram 0:62df7f96de34 51 }