Riad_ Bajraktarevic
/
Bajraktarevic_13_01_20
main
main.cpp@3:d9c6df85ff68, 2020-01-13 (annotated)
- Committer:
- riad
- Date:
- Mon Jan 13 17:34:00 2020 +0000
- Revision:
- 3:d9c6df85ff68
- Parent:
- 2:4eacbe2fa323
- Child:
- 4:6faa92e1841e
printb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
riad | 0:b44f9a2ebea2 | 1 | #include "mbed.h" |
riad | 0:b44f9a2ebea2 | 2 | #define BUTTON1 p14 |
riad | 0:b44f9a2ebea2 | 3 | //#define BUTTON! A1 |
riad | 0:b44f9a2ebea2 | 4 | |
riad | 0:b44f9a2ebea2 | 5 | int modifyBit(int x, unsigned char position, bool State); |
riad | 0:b44f9a2ebea2 | 6 | int lauflicht(bool richtung, int time, int &anz); |
riad | 0:b44f9a2ebea2 | 7 | void nibbleLeds(int value); |
riad | 0:b44f9a2ebea2 | 8 | void printb(uint8_t x); |
riad | 0:b44f9a2ebea2 | 9 | |
riad | 0:b44f9a2ebea2 | 10 | |
riad | 0:b44f9a2ebea2 | 11 | BusOut myleds(LED1,LED2,LED3,LED4); |
riad | 0:b44f9a2ebea2 | 12 | DigitalIn button(BUTTON1); |
riad | 0:b44f9a2ebea2 | 13 | |
riad | 0:b44f9a2ebea2 | 14 | const int INIT = 0x03; |
riad | 0:b44f9a2ebea2 | 15 | |
riad | 0:b44f9a2ebea2 | 16 | int main () |
riad | 0:b44f9a2ebea2 | 17 | { |
riad | 0:b44f9a2ebea2 | 18 | int anzahl, anz; |
riad | 0:b44f9a2ebea2 | 19 | uint8_t value = INIT; |
riad | 0:b44f9a2ebea2 | 20 | |
riad | 0:b44f9a2ebea2 | 21 | |
riad | 0:b44f9a2ebea2 | 22 | |
riad | 0:b44f9a2ebea2 | 23 | |
riad | 1:5fdd61b15b35 | 24 | } |
riad | 1:5fdd61b15b35 | 25 | |
riad | 1:5fdd61b15b35 | 26 | |
riad | 1:5fdd61b15b35 | 27 | int modifyBit (int x, uint8_t position, bool State) |
riad | 1:5fdd61b15b35 | 28 | { |
riad | 1:5fdd61b15b35 | 29 | int mask = 1 << position; |
riad | 1:5fdd61b15b35 | 30 | int state = int(State); |
riad | 1:5fdd61b15b35 | 31 | return (x & ~mask) | ((state << position) & mask); |
riad | 2:4eacbe2fa323 | 32 | } |
riad | 2:4eacbe2fa323 | 33 | |
riad | 2:4eacbe2fa323 | 34 | int lauflicht (bool richtung, int time, int &anz) |
riad | 2:4eacbe2fa323 | 35 | { |
riad | 2:4eacbe2fa323 | 36 | int i; |
riad | 2:4eacbe2fa323 | 37 | uint8_t lauf = 0x01; |
riad | 2:4eacbe2fa323 | 38 | |
riad | 2:4eacbe2fa323 | 39 | if(!richtung) |
riad | 2:4eacbe2fa323 | 40 | lauf = 0x08; |
riad | 2:4eacbe2fa323 | 41 | while(1) { |
riad | 2:4eacbe2fa323 | 42 | nibbleLeds(lauf&0x0F); |
riad | 2:4eacbe2fa323 | 43 | if(richtung) { |
riad | 2:4eacbe2fa323 | 44 | lauf = lauf << 1; |
riad | 2:4eacbe2fa323 | 45 | if(lauf > 8) |
riad | 2:4eacbe2fa323 | 46 | lauf = 0x01; |
riad | 2:4eacbe2fa323 | 47 | } else { |
riad | 2:4eacbe2fa323 | 48 | lauf = lauf >> 1; |
riad | 2:4eacbe2fa323 | 49 | if(lauf == 0) |
riad | 2:4eacbe2fa323 | 50 | lauf = 0x08; |
riad | 2:4eacbe2fa323 | 51 | } |
riad | 2:4eacbe2fa323 | 52 | if(button) |
riad | 2:4eacbe2fa323 | 53 | break; |
riad | 2:4eacbe2fa323 | 54 | wait_ms(time); |
riad | 2:4eacbe2fa323 | 55 | anz++; |
riad | 2:4eacbe2fa323 | 56 | } |
riad | 2:4eacbe2fa323 | 57 | return anz; |
riad | 3:d9c6df85ff68 | 58 | } |
riad | 3:d9c6df85ff68 | 59 | |
riad | 3:d9c6df85ff68 | 60 | void printb(uint8_t x) |
riad | 3:d9c6df85ff68 | 61 | { |
riad | 3:d9c6df85ff68 | 62 | for(int i=sizeof (x) << 3; i; i--) |
riad | 3:d9c6df85ff68 | 63 | putchar('0' + ((x>>(i-1))&1)); |
riad | 3:d9c6df85ff68 | 64 | printf("\n"); |
riad | 1:5fdd61b15b35 | 65 | } |