Mirza Mesic
/
tinf_test_mesic_mirza1
main_mit_mit_nibble_und_printbits1
main.cpp@2:4b37034bf874, 2020-01-13 (annotated)
- Committer:
- mirzamesic
- Date:
- Mon Jan 13 17:24:49 2020 +0000
- Revision:
- 2:4b37034bf874
- Parent:
- 1:b9fbf5790ee0
printb_bitausgabe
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mirzamesic | 0:2263bfee9a45 | 1 | #include "mbed.h" |
mirzamesic | 0:2263bfee9a45 | 2 | #define BUTTON1 p14 |
mirzamesic | 0:2263bfee9a45 | 3 | |
mirzamesic | 1:b9fbf5790ee0 | 4 | void nibbleLeds(int value); |
mirzamesic | 2:4b37034bf874 | 5 | void printb(uint8_t x); |
mirzamesic | 1:b9fbf5790ee0 | 6 | |
mirzamesic | 0:2263bfee9a45 | 7 | BusOut myleds(LED1,LED2,LED3,LED4); |
mirzamesic | 0:2263bfee9a45 | 8 | DigitalIn button(BUTTON1); |
mirzamesic | 0:2263bfee9a45 | 9 | |
mirzamesic | 1:b9fbf5790ee0 | 10 | const int INIT = 0x03; |
mirzamesic | 1:b9fbf5790ee0 | 11 | |
mirzamesic | 0:2263bfee9a45 | 12 | int main() |
mirzamesic | 0:2263bfee9a45 | 13 | { |
mirzamesic | 2:4b37034bf874 | 14 | |
mirzamesic | 1:b9fbf5790ee0 | 15 | uint8_t value = INIT; |
mirzamesic | 0:2263bfee9a45 | 16 | |
mirzamesic | 1:b9fbf5790ee0 | 17 | nibbleLeds(value); |
mirzamesic | 1:b9fbf5790ee0 | 18 | wait(0.1); |
mirzamesic | 1:b9fbf5790ee0 | 19 | } |
mirzamesic | 0:2263bfee9a45 | 20 | |
mirzamesic | 2:4b37034bf874 | 21 | void printb(uint8_t x) |
mirzamesic | 2:4b37034bf874 | 22 | { |
mirzamesic | 2:4b37034bf874 | 23 | |
mirzamesic | 2:4b37034bf874 | 24 | for(int i=sizeof(x)<<3; i; i--) |
mirzamesic | 2:4b37034bf874 | 25 | putchar('0'+((x>>(i-1))&1)); |
mirzamesic | 2:4b37034bf874 | 26 | printf("\n"); |
mirzamesic | 2:4b37034bf874 | 27 | |
mirzamesic | 2:4b37034bf874 | 28 | } |
mirzamesic | 2:4b37034bf874 | 29 | |
mirzamesic | 0:2263bfee9a45 | 30 | |
mirzamesic | 1:b9fbf5790ee0 | 31 | void nibbleLeds (int value) |
mirzamesic | 1:b9fbf5790ee0 | 32 | { |
mirzamesic | 0:2263bfee9a45 | 33 | |
mirzamesic | 1:b9fbf5790ee0 | 34 | myleds = value%16; |
mirzamesic | 1:b9fbf5790ee0 | 35 | |
mirzamesic | 1:b9fbf5790ee0 | 36 | } |