Stefan Simbürger / Mbed 2 deprecated Test_13012020

Dependencies:   mbed

Revision:
5:9df9f5f6fa57
Parent:
4:4f42c2344e23
Child:
6:7dc8014c6ed6
--- a/main.cpp	Mon Jan 13 17:52:51 2020 +0000
+++ b/main.cpp	Mon Jan 13 18:09:51 2020 +0000
@@ -4,6 +4,7 @@
 void nibbleLeds(int value);
 int lauflicht(bool richtung, int time, int&anz);
 void printb(uint8_t);
+int modifyBit(int x, unsigned char position, bool State);
 BusOut myleds(LED1, LED2, LED3, LED4);
 //DigitalIn button(BUTTON1);
 
@@ -17,7 +18,9 @@
     printf("anzahl= %d\n", anzahl);
     nibbleLeds(value);
     printb(value);
+    value = modifyBit(value, 2, 1);
     printb(myleds);
+    printb(modifyBit(INIT, 3, 1));
     wait(0.1);
 }
 
@@ -59,4 +62,11 @@
     for(int i=8; i; i--)
         printf("%d", (x>>(i-1)) &1);
     printf("\n");
+}
+
+int modifyBit(int x, uint8_t position, bool State)
+{
+    int mask = 1 << position;
+    int state = int(State);
+    return (x& ~mask) | ((state << position) & mask);
 }
\ No newline at end of file