Task 3.4.2

Fork of Task342 by Nicholas Outram

Committer:
noutram
Date:
Wed Sep 18 12:07:11 2019 +0000
Revision:
2:a98125cb0912
Parent:
0:62df7f96de34
2019

Who changed what in which revision?

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