initial commit and publish

Dependencies:   mbed

Committer:
kafka
Date:
Mon Jan 13 17:27:40 2020 +0000
Revision:
2:6a2101a16cef
Parent:
1:dcfefb503be4
Child:
3:c1dee77b3e02
third commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kafka 0:886ff6a91b2c 1 #include "mbed.h"
kafka 0:886ff6a91b2c 2 // #define BUTTON1 A1
kafka 0:886ff6a91b2c 3 #define BUTTON1 p14
kafka 0:886ff6a91b2c 4 BusOut myLeds(LED1,LED2,LED3,LED4);
kafka 0:886ff6a91b2c 5 DigitalIn button(BUTTON1);
kafka 0:886ff6a91b2c 6
kafka 0:886ff6a91b2c 7 void nibbleLeds(int value);
kafka 1:dcfefb503be4 8 void printb(uint8_t x);
kafka 2:6a2101a16cef 9 int modifyBit(int x, uint8_t position, bool State);
kafka 0:886ff6a91b2c 10 const int INIT = 0x03;
kafka 0:886ff6a91b2c 11
kafka 0:886ff6a91b2c 12
kafka 0:886ff6a91b2c 13 int main() {
kafka 0:886ff6a91b2c 14 int anzahl, anz;
kafka 0:886ff6a91b2c 15 uint8_t value = INIT;
kafka 0:886ff6a91b2c 16 // anzahl = lauflicht(true, 400, anz = 0);
kafka 0:886ff6a91b2c 17
kafka 0:886ff6a91b2c 18 printf("anzahl = %d\n", anzahl);
kafka 0:886ff6a91b2c 19 nibbleLeds(value);
kafka 1:dcfefb503be4 20 printb(myleds);
kafka 2:6a2101a16cef 21 value = modifyBit(value, 2, 1);
kafka 2:6a2101a16cef 22 printb(myleds);
kafka 2:6a2101a16cef 23 printb(modifyBit(value, 3, 1));
kafka 0:886ff6a91b2c 24 wait(0.1);
kafka 1:dcfefb503be4 25 }
kafka 0:886ff6a91b2c 26
kafka 1:dcfefb503be4 27 void nibbleLeds(int value) {
kafka 1:dcfefb503be4 28 myLeds = value % 16;
kafka 0:886ff6a91b2c 29 }
kafka 1:dcfefb503be4 30
kafka 1:dcfefb503be4 31 void printb(uint8_t x){
kafka 1:dcfefb503be4 32 for(int i = sizeof() << 3; i; i--)
kafka 1:dcfefb503be4 33 putchar('0' + ((x >> (i - 1)) & 1));
kafka 1:dcfefb503be4 34 printf("\n");
kafka 2:6a2101a16cef 35 }
kafka 2:6a2101a16cef 36
kafka 2:6a2101a16cef 37 int modifyBit(int x, uint8_t position, bool State){
kafka 2:6a2101a16cef 38 int mask = 1 << position;
kafka 2:6a2101a16cef 39 int state = int(State);
kafka 2:6a2101a16cef 40 return (x & ~mask) | ((state << position) & mask);
kafka 2:6a2101a16cef 41 }
kafka 2:6a2101a16cef 42