Mao jesephin
/
LaufTest
test
main.cpp@10:4e627d84406c, 2020-01-13 (annotated)
- Committer:
- jesephin
- Date:
- Mon Jan 13 18:13:12 2020 +0000
- Revision:
- 10:4e627d84406c
- Parent:
- 9:c2c6a6a50c14
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jesephin | 0:13c06c8c9762 | 1 | #include "mbed.h" |
jesephin | 6:9b523c7d1475 | 2 | #define BUTTON1 p14 //M3:push joystick pin |
jesephin | 0:13c06c8c9762 | 3 | //#define BUTTON1 A1 //NuCLEO: Taster A1 |
jesephin | 0:13c06c8c9762 | 4 | |
jesephin | 0:13c06c8c9762 | 5 | |
jesephin | 0:13c06c8c9762 | 6 | int modifyBit(int x,unsigned char position,bool State); |
jesephin | 0:13c06c8c9762 | 7 | int lauflicht(bool richtung,int time,int &anz); |
jesephin | 6:9b523c7d1475 | 8 | void nibbbleLeds(int value); |
jesephin | 0:13c06c8c9762 | 9 | void printb(uint8_t x); |
jesephin | 0:13c06c8c9762 | 10 | |
jesephin | 4:af513265bf6c | 11 | BusOut myleds(LED1,LED2,LED3,LED4); |
jesephin | 4:af513265bf6c | 12 | DigitalIn button(BUTTON1); |
jesephin | 0:13c06c8c9762 | 13 | |
jesephin | 6:9b523c7d1475 | 14 | const int INIT=0x03; |
jesephin | 0:13c06c8c9762 | 15 | |
jesephin | 0:13c06c8c9762 | 16 | int main() { |
jesephin | 0:13c06c8c9762 | 17 | int anzahl,anz; |
jesephin | 5:e8861f51128f | 18 | uint8_t value=INIT; |
jesephin | 0:13c06c8c9762 | 19 | |
jesephin | 0:13c06c8c9762 | 20 | anzahl=lauflicht(true,400,anz=0); |
jesephin | 0:13c06c8c9762 | 21 | printf("anzahl=%d\n",anzahl); |
jesephin | 0:13c06c8c9762 | 22 | |
jesephin | 7:8f0594cbc89a | 23 | nibbbleLeds(value); |
jesephin | 0:13c06c8c9762 | 24 | printb(value); |
jesephin | 0:13c06c8c9762 | 25 | value=modifyBit(value,2,1); |
jesephin | 0:13c06c8c9762 | 26 | printb(myleds); |
jesephin | 0:13c06c8c9762 | 27 | printb(modifyBit(INIT,3,1)); |
jesephin | 0:13c06c8c9762 | 28 | wait(0.1); |
jesephin | 0:13c06c8c9762 | 29 | |
jesephin | 0:13c06c8c9762 | 30 | } |
jesephin | 0:13c06c8c9762 | 31 | int lauflicht(bool richtung,int time,int&anz) |
jesephin | 1:842be995801a | 32 | { |
jesephin | 1:842be995801a | 33 | int i; |
jesephin | 10:4e627d84406c | 34 | uint8_t lauf=0x01; |
jesephin | 1:842be995801a | 35 | if(!richtung) |
jesephin | 1:842be995801a | 36 | lauf=0x08; |
jesephin | 1:842be995801a | 37 | |
jesephin | 2:fbffbc249ee9 | 38 | while(1) |
jesephin | 2:fbffbc249ee9 | 39 | { |
jesephin | 10:4e627d84406c | 40 | nibbbleLeds(lauf&0x0F); |
jesephin | 2:fbffbc249ee9 | 41 | if(richtung) |
jesephin | 2:fbffbc249ee9 | 42 | { |
jesephin | 2:fbffbc249ee9 | 43 | lauf=lauf<<1; |
jesephin | 2:fbffbc249ee9 | 44 | if(lauf>8) |
jesephin | 2:fbffbc249ee9 | 45 | lauf=0x01; |
jesephin | 2:fbffbc249ee9 | 46 | } |
jesephin | 2:fbffbc249ee9 | 47 | else{ |
jesephin | 2:fbffbc249ee9 | 48 | lauf=lauf>>1; |
jesephin | 2:fbffbc249ee9 | 49 | if(lauf==0) |
jesephin | 2:fbffbc249ee9 | 50 | lauf=0x08; |
jesephin | 2:fbffbc249ee9 | 51 | } |
jesephin | 2:fbffbc249ee9 | 52 | if(button) |
jesephin | 2:fbffbc249ee9 | 53 | break; |
jesephin | 2:fbffbc249ee9 | 54 | wait_ms(time); |
jesephin | 2:fbffbc249ee9 | 55 | anz++; |
jesephin | 2:fbffbc249ee9 | 56 | } |
jesephin | 2:fbffbc249ee9 | 57 | return anz; |
jesephin | 1:842be995801a | 58 | } |
jesephin | 10:4e627d84406c | 59 | |
jesephin | 10:4e627d84406c | 60 | void printb(uint8_t x) |
jesephin | 10:4e627d84406c | 61 | { |
jesephin | 10:4e627d84406c | 62 | for(int i=sizeof(x)<<3;i;i--) |
jesephin | 10:4e627d84406c | 63 | putchar('0')+((x>>(i-1)&1)); |
jesephin | 10:4e627d84406c | 64 | printf("\n"); |
jesephin | 10:4e627d84406c | 65 | } |
jesephin | 10:4e627d84406c | 66 | |
jesephin | 10:4e627d84406c | 67 | int modifyBit(int x, unit8_t position, bool State) |
jesephin | 10:4e627d84406c | 68 | { |
jesephin | 10:4e627d84406c | 69 | int mask = 1 << position; |
jesephin | 10:4e627d84406c | 70 | int state = int(State); |
jesephin | 10:4e627d84406c | 71 | return(x&~mask)|((state<<position)&mask); |
jesephin | 10:4e627d84406c | 72 | } |
jesephin | 10:4e627d84406c | 73 | |
jesephin | 10:4e627d84406c | 74 | |
jesephin | 10:4e627d84406c | 75 | |
jesephin | 2:fbffbc249ee9 | 76 | |
jesephin | 4:af513265bf6c | 77 | void nibbleLeds(int value) |
jesephin | 4:af513265bf6c | 78 | { |
jesephin | 4:af513265bf6c | 79 | myled=value%16; |
jesephin | 4:af513265bf6c | 80 | } |
jesephin | 4:af513265bf6c | 81 |