Stefan Kiegerl
/
run_test
run test
Diff: main.cpp
- Revision:
- 4:58f30b934b59
- Parent:
- 3:6041499f4c0f
- Child:
- 5:eb77a24b2d95
--- a/main.cpp Mon Jan 13 17:28:20 2020 +0000 +++ b/main.cpp Mon Jan 13 17:33:27 2020 +0000 @@ -5,6 +5,7 @@ void printb(uint8_t x); void nibbleLeds(int value); +int modifyBit(int x, uint8_t position, bool State); BusOut myleds(LED1, LED2, LED3, LED4); DigitalIn button(BUTTON1); @@ -16,9 +17,18 @@ nibbleLeds(value); printb(value); + value = modifyBit(value, 2, 1); + printb(myleds); + printb(modifyBit(INIT, 3, 1)); wait(0.1); } +int modifyBit(int x, uint8_t position, bool State) { + int mask = 1 << position; + int state = int(State); + return (x & ~mask) | ((state << position) & mask); +} + void printb(uint8_t x){ for(int i = sizeof(x)<<3; i; i--){ putchar('0'+((x>>(i-1))&1));