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