Mirza Mesic
/
tinf_test_mesic_mirza_fertig
vollProgramm
main.cpp@3:21631924f2f1, 2020-01-13 (annotated)
- Committer:
- mirzamesic
- Date:
- Mon Jan 13 17:32:26 2020 +0000
- Revision:
- 3:21631924f2f1
- Parent:
- 2:4b37034bf874
- Child:
- 4:6eb0d62c4fbf
main_mit_lauflicht
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 | 3:21631924f2f1 | 4 | int lauflicht(bool richtung, int time, int &anz); |
mirzamesic | 1:b9fbf5790ee0 | 5 | void nibbleLeds(int value); |
mirzamesic | 2:4b37034bf874 | 6 | void printb(uint8_t x); |
mirzamesic | 1:b9fbf5790ee0 | 7 | |
mirzamesic | 0:2263bfee9a45 | 8 | BusOut myleds(LED1,LED2,LED3,LED4); |
mirzamesic | 0:2263bfee9a45 | 9 | DigitalIn button(BUTTON1); |
mirzamesic | 0:2263bfee9a45 | 10 | |
mirzamesic | 1:b9fbf5790ee0 | 11 | const int INIT = 0x03; |
mirzamesic | 1:b9fbf5790ee0 | 12 | |
mirzamesic | 0:2263bfee9a45 | 13 | int main() |
mirzamesic | 0:2263bfee9a45 | 14 | { |
mirzamesic | 3:21631924f2f1 | 15 | int anzahl, anz; |
mirzamesic | 1:b9fbf5790ee0 | 16 | uint8_t value = INIT; |
mirzamesic | 3:21631924f2f1 | 17 | anzahl = lauflicht(true, 400, anz=0); |
mirzamesic | 3:21631924f2f1 | 18 | printf("anzahl = %d\n", anzahl); |
mirzamesic | 0:2263bfee9a45 | 19 | |
mirzamesic | 1:b9fbf5790ee0 | 20 | nibbleLeds(value); |
mirzamesic | 3:21631924f2f1 | 21 | printb(value); |
mirzamesic | 1:b9fbf5790ee0 | 22 | wait(0.1); |
mirzamesic | 1:b9fbf5790ee0 | 23 | } |
mirzamesic | 0:2263bfee9a45 | 24 | |
mirzamesic | 3:21631924f2f1 | 25 | int lauflicht(bool richtung, int time, int &anz) |
mirzamesic | 3:21631924f2f1 | 26 | { |
mirzamesic | 3:21631924f2f1 | 27 | int i; |
mirzamesic | 3:21631924f2f1 | 28 | uint8_t lauf = 0x01; |
mirzamesic | 3:21631924f2f1 | 29 | |
mirzamesic | 3:21631924f2f1 | 30 | if(!richtung) |
mirzamesic | 3:21631924f2f1 | 31 | lauf= 0x08; |
mirzamesic | 3:21631924f2f1 | 32 | while(1) { |
mirzamesic | 3:21631924f2f1 | 33 | nibbleLeds(lauf&0x0F); |
mirzamesic | 3:21631924f2f1 | 34 | if(richtung) { |
mirzamesic | 3:21631924f2f1 | 35 | |
mirzamesic | 3:21631924f2f1 | 36 | lauf = lauf << 1; |
mirzamesic | 3:21631924f2f1 | 37 | if(lauf>8) |
mirzamesic | 3:21631924f2f1 | 38 | lauf = 0x01; |
mirzamesic | 3:21631924f2f1 | 39 | |
mirzamesic | 3:21631924f2f1 | 40 | } else { |
mirzamesic | 3:21631924f2f1 | 41 | lauf = lauf >>1; |
mirzamesic | 3:21631924f2f1 | 42 | if(lauf == 0) |
mirzamesic | 3:21631924f2f1 | 43 | lauf = 0x08; |
mirzamesic | 3:21631924f2f1 | 44 | } |
mirzamesic | 3:21631924f2f1 | 45 | if(button) |
mirzamesic | 3:21631924f2f1 | 46 | break; |
mirzamesic | 3:21631924f2f1 | 47 | wait_ms(time); |
mirzamesic | 3:21631924f2f1 | 48 | anz++; |
mirzamesic | 3:21631924f2f1 | 49 | |
mirzamesic | 3:21631924f2f1 | 50 | } |
mirzamesic | 3:21631924f2f1 | 51 | return anz; |
mirzamesic | 3:21631924f2f1 | 52 | |
mirzamesic | 3:21631924f2f1 | 53 | |
mirzamesic | 3:21631924f2f1 | 54 | } |
mirzamesic | 3:21631924f2f1 | 55 | |
mirzamesic | 2:4b37034bf874 | 56 | void printb(uint8_t x) |
mirzamesic | 2:4b37034bf874 | 57 | { |
mirzamesic | 2:4b37034bf874 | 58 | |
mirzamesic | 2:4b37034bf874 | 59 | for(int i=sizeof(x)<<3; i; i--) |
mirzamesic | 2:4b37034bf874 | 60 | putchar('0'+((x>>(i-1))&1)); |
mirzamesic | 2:4b37034bf874 | 61 | printf("\n"); |
mirzamesic | 2:4b37034bf874 | 62 | |
mirzamesic | 2:4b37034bf874 | 63 | } |
mirzamesic | 2:4b37034bf874 | 64 | |
mirzamesic | 0:2263bfee9a45 | 65 | |
mirzamesic | 1:b9fbf5790ee0 | 66 | void nibbleLeds (int value) |
mirzamesic | 1:b9fbf5790ee0 | 67 | { |
mirzamesic | 0:2263bfee9a45 | 68 | |
mirzamesic | 1:b9fbf5790ee0 | 69 | myleds = value%16; |
mirzamesic | 1:b9fbf5790ee0 | 70 | |
mirzamesic | 1:b9fbf5790ee0 | 71 | } |