-1_modifyBit_return_mask

Dependencies:   mbed

Committer:
tina_dokic
Date:
Mon Jan 13 17:30:20 2020 +0000
Revision:
1:cb2dac24de1b
Parent:
0:d87fdef72565
Child:
2:11a1722e34a4
2_modififyBit_return(mask---)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tina_dokic 0:d87fdef72565 1 #include "mbed.h"
tina_dokic 0:d87fdef72565 2 // #define BUTTON1 pl4// M3:pusch joystick pin
tina_dokic 0:d87fdef72565 3 // #define BUTTON1 A1//NUCLEO:Taster A1
tina_dokic 0:d87fdef72565 4
tina_dokic 0:d87fdef72565 5 int modifyBit(int x,unsigned char position, bool State);
tina_dokic 0:d87fdef72565 6 int lauflicht(bool richtung, int time, int &anz);
tina_dokic 0:d87fdef72565 7 void nibbleLeds(int value);
tina_dokic 0:d87fdef72565 8 void printb(uint8_t x);
tina_dokic 0:d87fdef72565 9
tina_dokic 0:d87fdef72565 10 BusOut myleds(LED1,LED2,LED3,LED4);
tina_dokic 0:d87fdef72565 11 DigitalIn button(BUTTON1);
tina_dokic 0:d87fdef72565 12
tina_dokic 0:d87fdef72565 13 const int INIT= 0x03;
tina_dokic 0:d87fdef72565 14
tina_dokic 0:d87fdef72565 15
tina_dokic 0:d87fdef72565 16 int main() {
tina_dokic 0:d87fdef72565 17 int anzahl, anz;
tina_dokic 0:d87fdef72565 18 uint8_t value=INIT;
tina_dokic 0:d87fdef72565 19
tina_dokic 0:d87fdef72565 20 anzahl=lauflicht(true,400,anz=0);
tina_dokic 0:d87fdef72565 21 printf("anzahl=%d\n", anzahl);
tina_dokic 0:d87fdef72565 22
tina_dokic 0:d87fdef72565 23 nibbleLeds(value);
tina_dokic 0:d87fdef72565 24 printb(value);
tina_dokic 0:d87fdef72565 25 value=modifyBit(value,2,1);
tina_dokic 0:d87fdef72565 26 printb(modifyBit(INIT,3,1));
tina_dokic 0:d87fdef72565 27 wait(0.1);
tina_dokic 0:d87fdef72565 28 }
tina_dokic 1:cb2dac24de1b 29 int modifyBit(int x,unsigned char position, bool State){
tina_dokic 1:cb2dac24de1b 30 int mask=1<<position;
tina_dokic 1:cb2dac24de1b 31 int state=int(State);
tina_dokic 1:cb2dac24de1b 32 return (x & ~mask) | ((state << position) & mask);
tina_dokic 1:cb2dac24de1b 33
tina_dokic 1:cb2dac24de1b 34 }