Mao jesephin
/
LaufTest
test
main.cpp@2:fbffbc249ee9, 2020-01-13 (annotated)
- Committer:
- jesephin
- Date:
- Mon Jan 13 17:44:13 2020 +0000
- Revision:
- 2:fbffbc249ee9
- Parent:
- 1:842be995801a
- Child:
- 3:91bbd8d2f0c0
while
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jesephin | 0:13c06c8c9762 | 1 | #include "mbed.h" |
jesephin | 0:13c06c8c9762 | 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 | 0:13c06c8c9762 | 8 | void nibbbledLeds(int value); |
jesephin | 0:13c06c8c9762 | 9 | void printb(uint8_t x); |
jesephin | 0:13c06c8c9762 | 10 | |
jesephin | 0:13c06c8c9762 | 11 | BusOut myleds(LED1,LED2,LED3,LED4); |
jesephin | 0:13c06c8c9762 | 12 | DigitalIn button(Button); |
jesephin | 0:13c06c8c9762 | 13 | |
jesephin | 0:13c06c8c9762 | 14 | const int INIT=ox03; |
jesephin | 0:13c06c8c9762 | 15 | |
jesephin | 0:13c06c8c9762 | 16 | int main() { |
jesephin | 0:13c06c8c9762 | 17 | int anzahl,anz; |
jesephin | 0:13c06c8c9762 | 18 | unit8_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 | 0:13c06c8c9762 | 23 | nibbleLeds(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 | |
jesephin | 0:13c06c8c9762 | 32 | int modifyBit(intx,unit8_t position,bool State) |
jesephin | 0:13c06c8c9762 | 33 | { |
jesephin | 0:13c06c8c9762 | 34 | int mask = 1 << position; |
jesephin | 0:13c06c8c9762 | 35 | int state = int(State); |
jesephin | 0:13c06c8c9762 | 36 | return(x&~mask)|((state<<position)&mask); |
jesephin | 0:13c06c8c9762 | 37 | } |
jesephin | 0:13c06c8c9762 | 38 | |
jesephin | 0:13c06c8c9762 | 39 | int lauflicht(bool richtung,int time,int&anz) |
jesephin | 1:842be995801a | 40 | { |
jesephin | 1:842be995801a | 41 | int i; |
jesephin | 1:842be995801a | 42 | unit8_t lauf=0x01; |
jesephin | 1:842be995801a | 43 | if(!richtung) |
jesephin | 1:842be995801a | 44 | lauf=0x08; |
jesephin | 1:842be995801a | 45 | |
jesephin | 2:fbffbc249ee9 | 46 | while(1) |
jesephin | 2:fbffbc249ee9 | 47 | { |
jesephin | 2:fbffbc249ee9 | 48 | nibbleLeds(lauf&0x0F); |
jesephin | 2:fbffbc249ee9 | 49 | if(richtung) |
jesephin | 2:fbffbc249ee9 | 50 | { |
jesephin | 2:fbffbc249ee9 | 51 | lauf=lauf<<1; |
jesephin | 2:fbffbc249ee9 | 52 | if(lauf>8) |
jesephin | 2:fbffbc249ee9 | 53 | lauf=0x01; |
jesephin | 2:fbffbc249ee9 | 54 | } |
jesephin | 2:fbffbc249ee9 | 55 | else{ |
jesephin | 2:fbffbc249ee9 | 56 | lauf=lauf>>1; |
jesephin | 2:fbffbc249ee9 | 57 | if(lauf==0) |
jesephin | 2:fbffbc249ee9 | 58 | lauf=0x08; |
jesephin | 2:fbffbc249ee9 | 59 | } |
jesephin | 2:fbffbc249ee9 | 60 | if(button) |
jesephin | 2:fbffbc249ee9 | 61 | break; |
jesephin | 2:fbffbc249ee9 | 62 | wait_ms(time); |
jesephin | 2:fbffbc249ee9 | 63 | anz++; |
jesephin | 2:fbffbc249ee9 | 64 | } |
jesephin | 2:fbffbc249ee9 | 65 | return anz; |
jesephin | 1:842be995801a | 66 | } |
jesephin | 0:13c06c8c9762 | 67 | } |
jesephin | 2:fbffbc249ee9 | 68 |