Robin Handy
/
test1
main lauflicht test
main.cpp@5:c2a8fd8dede5, 2020-01-13 (annotated)
- Committer:
- rob117
- Date:
- Mon Jan 13 17:43:04 2020 +0000
- Revision:
- 5:c2a8fd8dede5
- Parent:
- 4:8d806106dbb0
- Child:
- 6:41d274ed6967
3 funktion lauflicht
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rob117 | 0:696d6bf92662 | 1 | #include "mbed.h" |
rob117 | 1:5756521122a8 | 2 | #define BUTTON1 p14 |
rob117 | 0:696d6bf92662 | 3 | |
rob117 | 0:696d6bf92662 | 4 | |
rob117 | 2:54c01dcbfbc8 | 5 | void nibbleLeds(int value); |
rob117 | 4:8d806106dbb0 | 6 | void printb(uint8_t x); |
rob117 | 5:c2a8fd8dede5 | 7 | int lauflicht(bool richtung, int time, int &anz); |
rob117 | 3:f82a2b7fb723 | 8 | |
rob117 | 0:696d6bf92662 | 9 | BusOut myleds(LED1, LED2, LED3, LED4); |
rob117 | 0:696d6bf92662 | 10 | DigitalIn button(BUTTON1); |
rob117 | 0:696d6bf92662 | 11 | |
rob117 | 2:54c01dcbfbc8 | 12 | |
rob117 | 2:54c01dcbfbc8 | 13 | |
rob117 | 2:54c01dcbfbc8 | 14 | |
rob117 | 2:54c01dcbfbc8 | 15 | |
rob117 | 0:696d6bf92662 | 16 | const int INIT = 0x03; |
rob117 | 0:696d6bf92662 | 17 | |
rob117 | 0:696d6bf92662 | 18 | int main() { |
rob117 | 3:f82a2b7fb723 | 19 | int anzahl, anz; |
rob117 | 3:f82a2b7fb723 | 20 | uint8_t value = INIT; |
rob117 | 3:f82a2b7fb723 | 21 | |
rob117 | 5:c2a8fd8dede5 | 22 | anzahl = lauflicht(true, 400, anz=0); |
rob117 | 5:c2a8fd8dede5 | 23 | printf("anzahl= %d\n", anzahl); |
rob117 | 5:c2a8fd8dede5 | 24 | |
rob117 | 3:f82a2b7fb723 | 25 | nibbleLeds(value); |
rob117 | 4:8d806106dbb0 | 26 | printb(value); |
rob117 | 3:f82a2b7fb723 | 27 | wait(0.1); |
rob117 | 0:696d6bf92662 | 28 | |
rob117 | 0:696d6bf92662 | 29 | |
rob117 | 2:54c01dcbfbc8 | 30 | } |
rob117 | 1:5756521122a8 | 31 | |
rob117 | 2:54c01dcbfbc8 | 32 | void nibbleLeds(int value){ |
rob117 | 2:54c01dcbfbc8 | 33 | myleds = value%16; |
rob117 | 2:54c01dcbfbc8 | 34 | } |
rob117 | 2:54c01dcbfbc8 | 35 | |
rob117 | 4:8d806106dbb0 | 36 | void printb(uint8_t x){ |
rob117 | 4:8d806106dbb0 | 37 | for(int i=sizeof(x)<<3; i; i--) |
rob117 | 4:8d806106dbb0 | 38 | putchar('0'+((x>>(i-1))&1)); |
rob117 | 4:8d806106dbb0 | 39 | printf("\n"); |
rob117 | 4:8d806106dbb0 | 40 | |
rob117 | 4:8d806106dbb0 | 41 | |
rob117 | 4:8d806106dbb0 | 42 | } |
rob117 | 5:c2a8fd8dede5 | 43 | |
rob117 | 5:c2a8fd8dede5 | 44 | int lauflicht(bool richtung, int time, int &anz){ |
rob117 | 5:c2a8fd8dede5 | 45 | int i; |
rob117 | 5:c2a8fd8dede5 | 46 | uint8_t lauf = 0x01; |
rob117 | 5:c2a8fd8dede5 | 47 | |
rob117 | 5:c2a8fd8dede5 | 48 | if(!richtung) |
rob117 | 5:c2a8fd8dede5 | 49 | lauf = 0x08; |
rob117 | 5:c2a8fd8dede5 | 50 | while(1){ |
rob117 | 5:c2a8fd8dede5 | 51 | nibbleLeds(lauf&0x0F); |
rob117 | 5:c2a8fd8dede5 | 52 | if(richtung){ |
rob117 | 5:c2a8fd8dede5 | 53 | lauf = lauf << 1; |
rob117 | 5:c2a8fd8dede5 | 54 | if(lauf>8) |
rob117 | 5:c2a8fd8dede5 | 55 | lauf = 0x01; |
rob117 | 5:c2a8fd8dede5 | 56 | } |
rob117 | 5:c2a8fd8dede5 | 57 | else { |
rob117 | 5:c2a8fd8dede5 | 58 | lauf = lauf >>1; |
rob117 | 5:c2a8fd8dede5 | 59 | if(lauf == 0) |
rob117 | 5:c2a8fd8dede5 | 60 | lauf = 0x08; |
rob117 | 5:c2a8fd8dede5 | 61 | } |
rob117 | 5:c2a8fd8dede5 | 62 | if(button) |
rob117 | 5:c2a8fd8dede5 | 63 | break; |
rob117 | 5:c2a8fd8dede5 | 64 | wait_ms(time); |
rob117 | 5:c2a8fd8dede5 | 65 | anz++; |
rob117 | 5:c2a8fd8dede5 | 66 | |
rob117 | 5:c2a8fd8dede5 | 67 | } |
rob117 | 5:c2a8fd8dede5 | 68 | return anz; |
rob117 | 5:c2a8fd8dede5 | 69 | |
rob117 | 5:c2a8fd8dede5 | 70 | } |